BuddyDev

Search

Display sitewide activity for followers only

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14368

    Hello,

    I would like to display activities of users that i’m following on the sitewide activities page using the buddypress follow plugin and I alsowant to disable activities of all members for logged in users, while logged out users can view activities of all members.

    1. logged in users can only view activities of users their following (it should be impossible to view all members activities i.e disable all members activity filter)
    2. logged out users can view activities of all members.

    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 21833
    Brajesh Singh on #14376

    Hi Tosin,
    If you are using the BuddyPress Follow plugin’s latest version from github, The following code will do it.

    
    
    /**
     * Filter sitewide activity to list following user's activity.
     *
     * @param array $args args.
     *
     * @return array
     */
    function buddydev_custom_list_activities_filter( $args ) {
    	if ( ! is_user_logged_in() || ! bp_is_members_directory() ) {
    		return $args;
    	}
    
    	// for logged in user, change scope to following.
    	$args['scope'] = 'following';
    
    	return $args;
    }
    
    add_filter( 'bp_after_has_activities_parse_args', 'buddydev_custom_list_activities_filter' );
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14385

    Hello

    Thank you for the code, I am using the latest update of buddypress follow from gith hub. I applied your code and it worked successfully but I noticed a problem which was when I logged into the site wide activities page the activities being displayed were that of users im following, but when I wanted to post a status update by clicking on status update form the activity tab filter automatically changed back to (all members) without clicking on the all members tab.

    I would like to disable the (all members) tab totally, if possible to remove it.

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14387

    I also tried this code you provided and I got the same result which is the filter keeps changing back to (all members) when I click on the status update form(what’s new form)

    /**
     * Set default activity directory tab for BuddyPress
     */
    function buddydev_set_default_activity_directory_tab() {
        // If user is not logged in or
        // If the scope is already set, do not do anything ok.
        if ( ! is_user_logged_in() || isset( $_COOKIE['bp-activity-scope'] ) ) {
            return ;
        }
        // additional check for activity dir
        if ( ! bp_is_activity_directory() ) {
            return ;
        }
        $tab = 'following'; // 'all', 'friends', 'groups', 'mentions'
        // Set scope to our needed tab,
        // In this case, I am setting to the 'friends' tab
        setcookie( 'bp-activity-scope', $tab,null, '/' );
        $_COOKIE['bp-activity-scope'] = $tab;
    }
    add_action( 'bp_template_redirect', 'buddydev_set_default_activity_directory_tab' );
  • Keymaster
    (BuddyDev Team)
    Posts: 21833
    Brajesh Singh on #14388

    Hi Tosin,
    Please change this line

    
    $args['scope'] = 'following';
    
    

    to

    
    
    $args['scope'] = 'follow';
    

    It will list the user follower activities even if all members tab is selected.

    you don’t need the second code.

    Also, if you want to remove the All members tab, I will suggest copying the buddypress/members/index.php from your theme(or bp-legacy) to your current theme /buddypress/members/index.php and remove it.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14389

    I applied the stated code but no changes. Activities are still changing automatically from (following) to (all members) upon clicking on staus update form

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14393

    I also changed my theme to wordpress tweenty fourteen theme and the problem still occurs.

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14417

    Hello Brajesh,

    I got it to work by editing the /buddypress/activity/index.php and removing the (all members) code. I later copied the edited file into my theme and applied the code stated below, now all logged in users are automatically viewing activities of people their following.

     /**
     * Filter sitewide activity to list following user's activity.
     *
     * @param array $args args.
     *
     * @return array
     */
    function buddydev_custom_list_activities_filter( $args ) {
    	if ( ! is_user_logged_in() || ! bp_is_members_directory() ) {
    		return $args;
    	}
    
    	// for logged in user, change scope to following.
    	$args['scope'] = 'follow';
    
    	return $args;
    }
    
    add_filter( 'bp_after_has_activities_parse_args', 'buddydev_custom_list_activities_filter' ); 

    The only bad effect is that it removed (all members) tab for logged out user, so I was forced to block access to site wide activity page for logged out users.

    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 21833
    Brajesh Singh on #14429

    Hi Tosin,
    Please feel free to restore your old template file.

    The problem lied with my code. I mistook for members directory. Have updated the code to

    
    /**
     * Filter sitewide activity to list following user's activity.
     *
     * @param array $args args.
     *
     * @return array
     */
    function buddydev_custom_list_activities_filter( $args ) {
    	if ( ! is_user_logged_in() || ! bp_is_activity_directory() ) {
    		return $args;
    	}
    
    	// for logged in user, change scope to following.
    	$args['scope'] = 'follow';
    
    	return $args;
    }
    
    add_filter( 'bp_after_has_activities_parse_args', 'buddydev_custom_list_activities_filter' );
    
    

    Also, this code should go to your theme’s functions.php or the bp-custom.php in plugins directory and not in template file.

    PS:- You can also just conditionally hide the All members tab by using a condition like. That will be a nice enhancement in addition to the above code.

    
    <?php if( ! is_user_logged_in() ) :?>
    ......link for showing the all members tab
    <?php endif;?>
    

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #14444

    Hello Brajesh,

    The stated code did not work it was this code stated below that worked

     /**
     * Set default activity directory tab for BuddyPress
     */
    function buddydev_set_default_activity_directory_tab() {
        // If user is not logged in or
        // If the scope is already set, do not do anything ok.
        if ( ! is_user_logged_in() || isset( $_COOKIE['bp-activity-scope'] ) ) {
            return ;
        }
        // additional check for activity dir
        if ( ! bp_is_activity_directory() ) {
            return ;
        }
        $tab = 'following'; // 'all', 'friends', 'groups', 'mentions'
        // Set scope to our needed tab,
        // In this case, I am setting to the 'friends' tab
        setcookie( 'bp-activity-scope', $tab,null, '/' );
        $_COOKIE['bp-activity-scope'] = $tab;
    }
    add_action( 'bp_template_redirect', 'buddydev_set_default_activity_directory_tab' ); 

    and I also applied the second code like this

     <?php if( ! is_user_logged_in() ) :?>
    		
    			<?php do_action( 'bp_before_activity_type_tab_all' ); ?>
    
    			<li class="selected" id="activity-all"><a href="<?php bp_activity_directory_permalink(); ?>" title="<?php esc_attr_e( 'The public activity for everyone on this site.', 'klein' ); ?>"><?php printf( __( 'All Members <span>%s</span>', 'klein' ), bp_get_total_member_count() ); ?></a></li>
    
    			<?php endif;?> 

You must be logged in to reply to this topic.

This topic is: not resolved