BuddyDev

Search

[Resolved] Display followers tab in members directory

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #35850

    Hello,

    Please how can I display a followers menu tab in the members directory using the follow plugin, currently only the following menu tab is visible but not followers tab.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2952
    Ravi on #35855

    Hello Tosin,

    Thank you for posting. Please look at the following reference for following:

    // Adding new members directory tab.
    https://github.com/r-a-y/buddypress-followers/blob/master/_inc/users/hooks.php#L556

    // Scoping for following.
    https://github.com/r-a-y/buddypress-followers/blob/master/_inc/users/hooks.php#L662

    Please let me know if you need further assistance.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #35857

    I added the code below to my bp-custom.php file but my site crashed

     /**
     * Add a "Following (X)" tab to the members directory.
     *
     * This is so the logged-in user can filter the members directory to only
     * users that the current user is following.
     *
     * @uses bp_follow_total_follow_counts() Get the following/followers counts for a user.
     */
    function bp_follow_add_following_tab() {
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    	$count = bp_follow_get_the_following_count();
    
    	if ( empty( $count ) ) {
    		return;
    	}
    ?>
    
    	<li id="members-following"><a href="<?php echo bp_loggedin_user_domain() . BP_FOLLOWING_SLUG ?>"><?php printf( __( 'Following <span>%d</span>', 'buddypress-followers' ), esc_html( $count ) ) ?></a></li>
    
    <?php
    }
    add_action( 'bp_members_directory_member_types', 'bp_follow_add_following_tab' ); 
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2952
    Ravi on #35858

    Hello Tosin,

    Your site is crashing because you are creating duplicate function which causing fatal. I have pointed you for showing how “Following” tab are working. Please make your own function for followers and let me know if you face any issue

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #35859

    Yeah I finally got it, thanks for making me brainstrom

     /**
     * Add a "Followers (X)" tab to the members directory.
     *
     * This is so the logged-in user can filter the members directory to only
     * users that the current user is following.
     *
     * @uses bp_follow_total_follow_counts() Get the following/followers counts for a user.
     */
    function bpfollow_add_followers_tab() {
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    	$count = bp_follow_get_the_followers_count();
    
    	if ( empty( $count ) ) {
    		return;
    	}
    ?>
    
    	<li id="members-followers"><a href="<?php echo bp_loggedin_user_domain() . BP_FOLLOWERS_SLUG ?>"><?php printf( __( 'My Followers <span>%d</span>', 'buddypress-followers' ), esc_html( $count ) ) ?></a></li>
    
    <?php
    }
    add_action( 'bp_members_directory_member_types', 'bpfollow_add_followers_tab' ); 
  • Participant
    Level: Guru
    Posts: 886
    Tosin on #35860

    But now how can I change the menu position for this code, My total menu items is 7, I want the (My Followers) tab to be positioned last

    • This reply was modified 3 years, 3 months ago by Tosin.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2952
    Ravi on #35862

    Hello Tosin,

    Thank you for the acknowledgement. Please try to add your function on priority something like 999 or so.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #35864

    It did not work

     function bpfollow_add_followers_tab() {
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    	$count = bp_follow_get_the_followers_count();
    
    	if ( empty( $count ) ) {
    		return;
    	}
    ?>
    
    	<li id="members-followers"><a href="<?php echo bp_loggedin_user_domain() . BP_FOLLOWERS_SLUG ?>"><?php printf( __( 'My Followers <span>%d</span>', 'buddypress-followers' ), esc_html( $count ) ) ?></a></li>
    
    <?php
    }
    add_action( 'bp_members_directory_member_types', 'bpfollow_add_followers_tab', 999 ); 
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2952
    Ravi on #35869

    Hello Tosin,

    Are you using BuddyPress Nouveau or legacy template pack.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #35871

    I am using legacy template

The topic ‘ [Resolved] Display followers tab in members directory’ is closed to new replies.

This topic is: resolved