Skip to:
Content
Pages
Categories
Search
Top
Bottom

Execute bp_activity_add_user_favorite function


  • davidpaulalbert
    Member

    @davidpaulalbert

    Hi. I’m developing a plugin for Buddypress where I’d like to utilize the bp_activity_add_user_favorite function.

    I’m executing a PHP function (via AJAX) when a user clicks on a button. Within that function I’m calling bp_activity_add_user_favorite as follows:
    do_action( ‘bp_activity_add_user_favorite’, $activity_id, $user_id );

    I’ve verified that I have both valid $activity_id and $user_id values (matching up to actual db records), but bp_activity_add_user_favorite doesn’t seem to be executing because the favorite in question isn’t saving for that user. It’s my understanding that bp_activity_add_user_favorite will populate both the bp_activity_meta and user_meta tables respectively. First, is that correct, and any ideas why this might not be executing?

    Thanks in advance for anyone’s insight!

Viewing 1 replies (of 1 total)

  • shanebp
    Moderator

    @shanebp

    I think you’re confused about what do_action actually does.
    It provides a hook that you can access with add_action.

    Why not call just call bp_activity_add_user_favorite directly in the php function called by ajax ?

    something like:
    `
    $add_fav = bp_activity_add_user_favorite( $activity_id, $user_id );
    if( $add_fav ) echo “1”; //true – it worked
    else echo “0”; //false – it failed
    `

    Then handle the response how ever you want back in your ajax function

Viewing 1 replies (of 1 total)
  • The topic ‘Execute bp_activity_add_user_favorite function’ is closed to new replies.
Skip to toolbar