BuddyDev

Search

by Brajesh Singh

Permalink: #778

Add a User to a perticular group when User account is activated

add_action( 'bp_core_activated_user', 'bpdev_join_group_on_signup');

function bpdev_join_group_on_signup( $user_id ){

    $group_id = 3;//change it to the group id you want the user to join

    groups_join_group( $group_id, $user_id );

}

#buddypress #bp-hacks

by Brajesh Singh

Permalink: #428

Extending Breadcrumb Trail plugin for BuddyPress breadcrumb navigation

//filter and append our items to breadcrumb trails
add_filter('breadcrumb_trail_items', 'hibuddy_include_bp_items',10,2);

function hibuddy_include_bp_items($trail, $args){


     global $bp;

     //current action
     $action = isset( $bp->canonical_stack['action'] ) ? $bp->canonical_stack['action'] : '' ;
     $component = isset( $bp->canonical_stack['component'] ) ? $bp->canonical_stack['component'] : '';
     $action_variables = isset( $bp->canonical_stack['action_variables'] ) ?  $bp->canonical_stack['action_variables'] : array();

     $trail_end = '';

     //is user component
     if( bp_is_user() ){
         //remove trail_end
        unset($trail['trail_end']);
        //add Members Page as Link
        $trail[] = "<a href='".get_permalink($bp->pages->members->id)."'>".get_the_title($bp->pages->members->id)."</a>"; 


        //if component is empty, it will just list the user display name as end point
        //we may improve it to show the default component title instead in future

        if( empty( $component ) ){
            $trail['trail_end'] = bp_get_displayed_user_fullname ();
        }else{
            //if we are here, we are most probably on a component screen of user
            $trail[] = bp_core_get_userlink(bp_displayed_user_id());
            //find the details about current nav item
            $nav_details = hibuddy_find_nav_details($bp->bp_nav, $component);
            //let us keep the name of current nav menu as end point
            $trail_end = $nav_details['name'];

            //are we doing some action for the component
            if( !empty( $action ) ) {
                //yes, then let us link to the parent component on user
                $trail[] = "<a href='". $nav_details['link']."'>".$nav_details['name']."</a>";

                $subnav_details = hibuddy_find_subnav_details( $component, $action );

                //let us keep that sub nav action name as the end point
                $trail_end = $subnav_details['name'];

            }

            if( !empty( $action_variables ) ){

                //is some action_variable set
                //if yes, let us append the parent action link to the breadcrumb
                $trail[] = "<a href='". $subnav_details['link']."'>".$subnav_details['name']."</a>";

                $trail_end = array_pop( $action_variables );

                foreach( $action_variables as $action_name )
                    $trail[] = ucwords(str_replace('-', ' ', $action_name));

               $trail_end = ucwords( str_replace('-', ' ', $trail_end ) );
            }

        }



    }elseif( bp_is_active('groups') && bp_is_group() ){

         unset($trail['trail_end']);
         //let us append the group parent page as link       
         $trail[] = "<a href='".get_permalink($bp->pages->groups->id)."'>".get_the_title($bp->pages->groups->id)."</a>"; 


        //get the current group details
         $current_group = groups_get_current_group();

         //if no action is set, we are on group home page
         if( empty( $action ) ){
            $trail['trail_end'] = bp_get_group_name( $current_group );
         }else{
            //we are on any of group internal page

            $trail[]= "<a href='".  bp_get_group_permalink( $current_group )."'>".  bp_get_group_name( $current_group )."</a>";

            $subnav_details = hibuddy_find_subnav_details( $current_group->slug, $action );


            $trail_end = $subnav_details['name'];

            if( !empty( $action_variables ) ){
                $trail[] = "<a href='". $subnav_details['link']."'>".$subnav_details['name']."</a>";



                $trail_end = array_pop( $action_variables );
                foreach( $action_variables as $action_name )
                    $trail[] = ucwords( str_replace('-', ' ', $action_name ) );

               $trail_end = ucwords(str_replace('-', ' ',$trail_end ));


            }


        }



    }

//that's all folks for the User/group
//what other components do you use,
//I was planning to write the 3rd section to handle the non core components having their own single pages(e.g. events etc)
// but I need some suggestion about one of the plugins to see if I can have a generic way of doing it
    //append trail end
     if( !empty( $trail_end ) )
            $trail['trail_end'] = $trail_end;

     return $trail;

}
/**
 * 
 * Iterates over a multi dimensional array and finds the array item that has a slug name which matches item name
 * @global type $bp
 * @param mixed $collection array of nav items
 * @param type $item_name slug name to match against
 * @return mixed|boolean
 */
function hibuddy_find_nav_details($collection, $item_name){



    foreach( $collection as $nav_item){

        if($nav_item['slug']== $item_name){

            //let us manipulate the link
            if ( bp_loggedin_user_domain() ) 
            $nav_item['link'] = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $nav_item['link'] );

            return $nav_item;

        }
    }

    return false;
}
/**
 * Find the subnav array 
 * @global type $bp
 * @param type $component : component name groups etc
 * @param type $action which action eg. admin/forums etc
 * @return mixed array of sub nav item details 
 */
function hibuddy_find_subnav_details( $component, $action ){
    global $bp;

    $main_nav = $bp->bp_options_nav[$component];


    return hibuddy_find_nav_details( $main_nav, $action );

}

#buddypress #breadcrumb #bp-hacks

by Brajesh Singh

Permalink: #230

BuddyBlog change settings example to post to single category and some more

add_filter('buddyblog_post_form_settings', 'buddyblog_custom_form_settings');
function buddyblog_custom_form_settings( $settings ){

    unset( $settings['upload_count'] );
    unset( $settings['tax'][ 'post_tag'] );//no need to show posts tag

    $category = get_category_by_slug( 'blog' );

    $settings['tax']['category']['include'] = array( 0 => $category->term_id );

  return $settings;  
}

@buddyblog #buddypress #buddyblog

by Brajesh Singh

Permalink: #221

BuddyBlog Redirect to single post on new post creation or post update


//redirect to single post on save/update //in future, I will add two different options for new post/update post add_action( 'bsfep_post_saved', 'buddyblog_redirect_on_post' ); function buddyblog_redirect_on_post( $post_id ){ $post = get_post( $post_id ); $post_type = get_post_type( $post ); $post_type_details = get_post_type_object( $post_type ); $message = sprintf( __( '%s Saved as %s successfully.', 'bsfep' ), $post_type_details->labels->singular_name, get_post_status( $post_id ) ); bp_core_add_message( $message ); bp_core_redirect( get_permalink( $post_id ) ); }

@buddyblog #buddypress #buddyblog

by Brajesh Singh

Permalink: #212

Show Posts from a perticular category only on user profile, other should link to the main site when using BuddyBlog

add_filter( 'buddyblog_show_posts_on_profile', 'buddyblog_custom_permalinks_filter', 10, 2 );
function buddyblog_custom_permalinks_filter( $do_filter, $post ){

    $category = get_category_by_slug( 'blog' );

    $post_categories = get_the_category( $post->ID );

    $post_cat_ids = wp_list_pluck( $post_categories, 'term_id' );
    //if it is in blog category, show on profile
    if( in_array( $category->term_id, $post_cat_ids ) )
            return true;

    return $do_filter;

}

#buddypress #buddyblog @buddyblog

by Brajesh Singh

Permalink: #190

Remove Friendship Button on User Profile(removes add/remove/Cancel Friendship button from user profile)

//remove friendship button oon Single User profile
add_action('bp_init','bp_custom_remove_friendship_btn_on_profile');
function bp_custom_remove_friendship_btn_on_profile(){

    if ( has_action( 'bp_member_header_actions', 'bp_add_friend_button' ) ) {
            remove_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 );

    }

}

#buddypress #friends #bp-hacks

by Brajesh Singh

Permalink: #182

Hide Friends of a User from Other users. Only Site Admin and the User can see his/her Friends

/**
 * Hide User Friends from Other Users
 * Only Admin or the user himself can see friends
 */
add_action('bp_friends_setup_nav','bpdev_custom_hide_friends_if_not_self');

function bpdev_custom_hide_friends_if_not_self(){
    if( bp_is_my_profile() || is_super_admin() )
        return ;

    bp_core_remove_nav_item( 'friends' );

}


You can put the above code in bp-custom.php

#buddypress #friends #bp-hack

by Brajesh Singh

Permalink: #170

Remove Activity Link(Permalink) from Activity time since on Activity Lists


/** * Remove permalink link from time since on activity list */ add_filter( 'bp_activity_permalink', 'bpdev_custom_rtemove_perlink_from_timesince',10,2 ); function bpdev_custom_rtemove_perlink_from_timesince( $time_since, $activity ){ $action = $activity-&gt;action ; $time_since = '<span class="time-since">' . bp_core_time_since( $activity-&gt;date_recorded ) . '</span>'; $content = sprintf( '%1$s %2$s', $action, $time_since ); return $content; }

You can put the above code in your theme's functions.php or bp-custom.php in plugins directory

#buddypress #activity #bp-hack

by Brajesh Singh

Permalink: #66

Custom Facebook Login/registration Button with BuddyPress Facebook Connect Plugin

The code below allows you to use your own custom login/registration button with facebook connect plus plugin

Please put the following code in your functions.php or bp-custom.php

    function bpdev_custom_fb_login_button( $btn_label = '' ){
        echo bpdev_custom_get_fb_login_button( $btn_label );
    }

    function  bpdev_custom_get_fb_login_button( $btn_label = '' ){

        $fb = BPDevFacebook::get_instance();
        //if user is already logged in, do not show the button
        if( $fb->get_current_user_id() || is_user_logged_in() || !bp_get_signup_allowed() )
                return;


        $helper = BPDevFBUserSettings::get_instance();

         $permissions = $helper->get_permissions();
            //pass a label for chaning the login text
         return "<div class='fb-login-button' data-scope='".$permissions."'><a href='#'>".$label."</a></div>";//so incase the custom text is given

     }

You will Need to call/show the button using

<?php bpdev_custom_fb_login_button('Login Please');?>

To make this button work, we will need to add following javascript code

//bind facebook login button click
jq('body').on('click','.fb-login-button a', function(){

   var fb_scope=jq(this).parent().attr('data-scope');
    //console.log(fb_scope);
    FB.login(function (response) {
       if (response.status == "connected") {
                  //alert('We are debugging our app. Please be patient...');
          window.location.reload();
       }
       else {
           //console.log("Error" + response);
       }
    }, {scope: fb_scope}); 
    return false;
});

You can put that js code in your theme's js file

Once you are done with that you can use following css classes to change the image etc.

div.fb-login-button{
 }
div.fb-login-button a{
}
div.fb-login-button a:hover{

}

Hope that helps.

#buddypress, #fb-connect-plus, #custom, #plugins