Get 15% off on all our plugins, themes and memberships till 30th Nov. Use coupon: BLACKFRIDAY2020.



by Brajesh Singh

Permalink: #788

Make user autojoin to the current Group if They register from group page using Bp Ajax registration plugin

class BPAjaxR_Autojoin_Current_Group{ private static $instance; private function __construct() { add_action( 'bp_after_account_details_fields', array( $this, 'add_group_field' ) ); add_action( 'bp_signup_usermeta', array( $this, 'update_signup_meta' ) ); add_action( 'bp_core_activated_user', array( $this, 'join_on_activation' ), 10, 3 ); } /** * Get the singleton instance * @return BPAjaxR_Autojoin_Current_Group */ public static function get_instance(){ if( !isset ( self::$instance ) ) self::$instance = new self(); return self::$instance; } /** * add current group as hidden field on registration page */ public function add_group_field() { if( !bp_is_group() ) return ; echo "<input type='hidden' name='current-group' value='". bp_get_group_id( groups_get_current_group() )."' />"; } /** * Add the group field to signup meta * @param type $meta */ public function update_signup_meta( $meta ) { //check if the group field is set if( $_POST['current-group'] ) $meta['group_to_join'] = (int) $_POST['current-group']; return $meta; } /** * Make user join the group when account is activated * @param type $user_id * @param type $key * @param type $user */ public function join_on_activation( $user_id, $key, $user ) { $meta = $user['meta']; if( empty( $meta['group_to_join'])) return ; $group_id = (int) $meta['group_to_join']; groups_join_group($group_id, $user_id ); } } //initialize BPAjaxR_Autojoin_Current_Group::get_instance();

Please put the above code in bp-custom.php

#bp-hacks, #registration #bp-ajax-registration

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: #762

Custom listing of Recent Visitors

/* custom Recent visitor code to list it anywhere for logged in user */
$visitors = visitors_get_recent_visitors(get_current_user_id(), 5);//pass the user id for which we are retriving and how many we want
foreach( (array) $visitors as $visitor_id ){

    echo bp_core_get_userlink( $visitor_id );//display the name of the 

    //bp_core_get_user_displayname( $visitor_id ); //use it to fetch the user display name
    //bp_core_get_user_domain( $visitor_id ); //use it to get user profile url
    //bp_core_fetch_avatar( array('item_id'=> $visitor_id, 'height'=>25, 'width'=> 25)); //fetch user avatar


by bphelp

Permalink: #719

Add Post Form To BuddyDev's BuddyPress Activity Shortcode Plugin

// Using BuddyDev's BuddyPress Activity Shortcode Plugin you can add a post form
// by adding the below code to bp-activity-as-shortcode.php. Just above line 84 
// where you see this: <?php if($title): ?> then above that add this:
<?php if ( is_user_logged_in() ) : ?>
    <?php locate_template( array( 'activity/post-form.php'), true ); ?>
<?php endif; ?><br />


by Brajesh Singh

Permalink: #696

Get Poke Count for a User

function bp_poke_get_poke_count( $user_id ){ $pokes = bp_get_user_meta( $user_id, 'pokes', true ); if( ! empty( $pokes ) ) return count( $pokes ); return 0; }

You can pass bp_displayed_user_id() while calling this function to show the poke count of diplayed user. To show the poke count of logged in user, pass get_current_user_id()

#bp-poke #bp-hacks

by Brajesh Singh

Permalink: #679

Fix avatar visibility problem on BuddyPress Multiblog/Multinetwork

function bpdev_fix_avatar_dir_path( $path ){ if ( is_multisite() && BP_ENABLE_MULTIBLOG ) $path = ABSPATH . 'wp-content/uploads/'; return $path; } add_filter( 'bp_core_avatar_upload_path', 'bpdev_fix_avatar_dir_path', 1 ); //fix the upload dir url function bpdev_fix_avatar_dir_url( $url ){ if ( is_multisite() ) $url = network_home_url('/wp-content/uploads') ; return $url; } add_filter( 'bp_core_avatar_url', 'bpdev_fix_avatar_dir_url', 1 );

#bp-hacks #avatar #multinetwork #multisite

by Brajesh Singh

Permalink: #662

Show the faces of users who liked a BuddyPress Activity

if( !function_exists('bp_activity_add_meta')):
function bp_activity_add_meta( $activity_id, $meta_key, $meta_value ) {
    global $wpdb, $bp;

    // Make sure activity_id is valid
    if ( !is_numeric( $activity_id ) )
        return false;

    // Sanitize key
    $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );

    // Sanitize value
    if ( is_string( $meta_value ) )
        $meta_value = stripslashes( esc_sql( $meta_value ) );

    // Maybe, just maybe... serialize
    $meta_value = maybe_serialize( $meta_value );

    $wpdb-&gt;query( $wpdb-&gt;prepare( "INSERT INTO {$bp-&gt;activity-&gt;table_name_meta} ( activity_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $activity_id, $meta_key, $meta_value ));

    //should we consider invalidating the cache
    wp_cache_delete( 'bp_activity_meta_' . $activity_id . '_' . $meta_key,  'bp' );

    // Victory is ours!
    return true;
add_action( 'bp_activity_add_user_favorite', 'bpdev_track_user_favorite', 10, 2);

function bpdev_track_user_favorite( $activity_id, $user_id ){

    bp_activity_add_meta( $activity_id, 'favorited_by_user', $user_id );
add_action( 'bp_activity_remove_user_favorite', 'bpdev_track_user_unfavorite', 10, 2);

function bpdev_track_user_unfavorite( $activity_id, $user_id ){

    bp_activity_delete_meta( $activity_id, 'favorited_by_user', $user_id );

//show faces, yay!

add_action( 'bp_activity_entry_content', 'bpdev_show_who_favorited_activities' );
function bpdev_show_who_favorited_activities(){
    $output = '';
    $favorited_users = bp_activity_get_meta( bp_get_activity_id(), 'favorited_by_user' );
    if( !empty( $favorited_users ) ){

        foreach( (array) $favorited_users as $user_id )
            $output .= "<a href='" . bp_core_get_user_domain ( $user_id ) . "'>". bp_core_fetch_avatar ( array( 'type'=&gt; 'thumb', 'height'=&gt; 25, 'width'=&gt;25, 'item_id'=&gt; $user_id ) ) . "</a>";

    if( $output )
        echo "<div class='clearfix activity-favorited-by'>{$output}</div>";

Put the above code in bp-custom.php

#activity #bp-hacks

by Brajesh Singh

Permalink: #637

Get the total number of favorites accumulated by a user on his activities

 * Get the total no. of favorites accumulated by a user on his activities 
 * @global type $bp
 * @global type $wpdb
 * @param int $user_id
 * @return int count of total favories by other users on given users activity 
function bpdev_count_user_acivity_favs( $user_id ){

    global $bp, $wpdb;
    $query =$wpdb->prepare("SELECT SUM(meta_value) as total FROM {$bp->activity->table_name_meta} WHERE meta_key = %s AND activity_id IN ( SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d)", 'favorite_count', $user_id );

    return (int) $wpdb->get_var( $query );


#activity, #bp-hacks

by bphelp

Permalink: #614

Add Xprofile fields to the members directory

// Here is one way you could add xprofile fields name as well as the value to the members directory! 
// Just remember to replace "Field-Name" with the names of your fields in the 5 variables in my code. 
// Also remember the field name is case sensitive. If you notice the pattern of 5 in my code you can 
// easily see how to add more fields if you need them. You can also use the div class bph_xprofile_fields 
// to adjust the CSS in your stylesheet. Place this code in bp-custom.php:
add_action('bp_directory_members_item', 'bphelp_dpioml');
function bphelp_dpioml(){
       if( is_user_logged_in() && bp_is_members_component() ) { ?>
        <div class="bph_xprofile_fields" style=" margin-left: 25%;">
                          <?php echo $bphelp_my_profile_field_1  ?>:&nbsp;<?php echo bp_member_profile_data( 'field='.$bphelp_my_profile_field_1 );  ?><br />
                          <?php echo $bphelp_my_profile_field_2 ?>:&nbsp;<?php echo bp_member_profile_data( 'field='.$bphelp_my_profile_field_2 ); ?><br />
                          <?php echo $bphelp_my_profile_field_3 ?>:&nbsp;<?php echo bp_member_profile_data( 'field='.$bphelp_my_profile_field_3 ); ?><br />
                          <?php echo $bphelp_my_profile_field_4 ?>:&nbsp;<?php echo bp_member_profile_data( 'field='.$bphelp_my_profile_field_4 ); ?><br />
                          <?php echo $bphelp_my_profile_field_5 ?>:&nbsp;<?php echo bp_member_profile_data( 'field='.$bphelp_my_profile_field_5 ); ?><br />


by bphelp

Permalink: #576

Remove groups tab from user profile

// Remove groups tab from profile
// adjust accordingly to remove other items! Simple huh?
// Enjoy!
function bphelp_remove_groups_from_profile(){