• Resolved Henry Wright

    (@henrywright)


    Hi r-a-y,

    I was wondering about the usage of do_action_ref_array in the save function in bp-follow-classes.php.

    For example:

    do_action_ref_array( 'bp_follow_after_save', array( &$this ) );

    My aim is to hook in but I’m having trouble accessing $this inside my callback.

    function my_callback( &$arg ) {
        // Do something.
    }
    add_action( 'bp_follow_after_save', 'my_callback' );

    I’d usually do something like echo $arg[0] but in this case $this is an object.

    Considering it’s an object, would I do this instead $arg[0]->leader_id?

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author r-a-y

    (@r-a-y)

    Hi henrywright,

    You use the hook like this:

    function my_callback( $follow ) {
        $leader_id = $follow->leader_id;
    }
    add_action( 'bp_follow_after_save', 'my_callback' );

    Since $follow is an object (or $arg) in your old example, you can just reference it as an object immediately.

    Let me know if you have any other Qs.

    Thread Starter Henry Wright

    (@henrywright)

    Hi r-a-y

    Thanks for the explanation… I was expecting $follow to be an array and the first index to be the object.

    Plugin Author r-a-y

    (@r-a-y)

    I can see why you would think that by the do_action_ref_array() function name ??

    Thread Starter Henry Wright

    (@henrywright)

    It was more the 3rd example under Notes in the do_action_ref_array article that threw me. See here:

    https://codex.www.ads-software.com/Function_Reference/do_action_ref_array#Notes

    Plugin Author r-a-y

    (@r-a-y)

    Ahh, that documentation is a little confusing.

    I usually just var_dump() the variable if I’m not sure about what is being passed.

    Will be interesting to know what you’re doing on the after follow save hook ??

    Thread Starter Henry Wright

    (@henrywright)

    I really should learn to use var_dump() a lot more! Thanks for the tip ??

    I wished I was doing something far more interesting with the after follow hook but on this occasion I’m just sending an email notification to my admin account each time a new follow event happens. I want to get a feel for how often people are following, then unfollowing, then re-following the same user. I call it ‘follow’ spam.

    For example, User X follows User Y which results in a notification being sent to User Y. User X ‘hopes’ the notification will serve as a ‘nudge’ to follow back. When User Y doesn’t follow back, User X hits unfollow. Then after a few days, User X starts the process again, hoping the fresh ‘nudge’ will result in a follow back. You might have seen these spammy tactics on Twitter?

    If my admin email account has multiple follow notifications all from User X over the course of a few days, then I’ll mark User X as a spammer.

    I’m sure there’s a far more sophisticated way to approach this but I thought it’ll work on a small website and is a quick win.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Usage of do_action_ref_array in bp-follow-classes.php’ is closed to new replies.