• Is there another way to get the User ID of the leader when a follow takes place from the /members page?

    bp_displayed_user_id() doesn’t work here, when there are many members shown at once.

    I need the leader ID in order to send e-mail notifications that include a link to the leader’s followers page, e.g. /username/followingslug, and also to build their settings link for disabling notifications.

    https://www.ads-software.com/plugins/buddypress-followers/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter adamt19

    (@adamt19)

    I tried getting user_id for leader this way:

    function mm_get_context_user_id($user_id=false) {
    
    if ( bp_is_my_profile() || !is_user_logged_in() ) {
     return false;
     }
     if( !$user_id )
     $user_id = bp_get_member_user_id();//for members loop
     if( !$user_id && bp_is_user() ) //for user profile
     $user_id = bp_displayed_user_id();
    
     return apply_filters( 'mm_get_context_user_id', $user_id );
    }

    and then in the e-mail message function:

    $user_id = mm_get_context_user_id();

    but once again it only works when I’m following someone while looking at their profile. The members loop use-case is still broken.

    Plugin Author r-a-y

    (@r-a-y)

    When writing your plugin, you should use the bp_follow_start_following hook:
    https://github.com/r-a-y/buddypress-followers/blob/1.2.x/_inc/bp-follow-functions.php#L43

    This hook fires when a follow relationship is saved into the DB. The object includes the 'leader_id' as a property, which you can use to do what you want.

    Also, keep in mind that BP Follow v1.3 will include a follow_type property. To make sure you don’t run into conflicts with other, potential follow types, you should make sure the follow_type property is empty. This will ensure that your plugin only affects users.

    Hope that helps!

    Thread Starter adamt19

    (@adamt19)

    Sorry – need a little more help! I’ve been customizing all of my e-mails by just filtering the existing functions that send them (activation, forgot password, new follower, new message) so I’m not sure what to do with bp_follow_start_following D:

    are you saying add_filter or re-define to bp_follow_start_following in my plugin to call wp_mail at the end (and then I’d have to disable the other message (bp_follow_new_follow_email_notification)?

    or something else?

    Thread Starter adamt19

    (@adamt19)

    welp, doesn’t look like I can redefine it. hm

    Thread Starter adamt19

    (@adamt19)

    So now I’m guessing I need to add_action to bp_follow_start_following? but..

    bp_follow_start_following still derives the leader_id from bp_displayed_user_id(), which I’m guessing won’t work for me anyway, since I have [follow] buttons on the /members page?

    Plugin Author r-a-y

    (@r-a-y)

    adamt19 – See if applying the following commit will fix your problem:
    https://github.com/r-a-y/buddypress-followers/commit/1655082d0f9fcfd04302972a0d3f9ebd9bce1ee1

    I’m not 100% sure if this addresses your issue though.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting leader_id from members page’ is closed to new replies.