Take a look at bp_dtheme_mark_activity_favorite
and bp_dtheme_unmark_activity_favorite
in bp-themes/bp-default/_inc/ajax.php
I actually found that last night shortly after posting last night but have not been able to get it to work. I have tried removing it as an action, adding a filter to it, and adding my own custom function as an action 🙁
Aha, nevermind figured it out. I was being dumb:
I knew it was an ajax function, but forgot to add the whole ‘wp_ajax’ string to the initial remove_action.
This ended up being my final code. Sure I could have done it a bit easier but just wanted to cover the base of getting it done first off.
remove_action( 'wp_ajax_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
remove_action( 'wp_ajax_nopriv_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
remove_action( 'wp_ajax_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
remove_action( 'wp_ajax_nopriv_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
function custom_like_text(){
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
if ( bp_activity_add_user_favorite( $_POST['id'] ) )
_e( '[custom unlike text]', 'buddypress' );
else
_e( '[custom like text]', 'buddypress' );
exit;
}
function custom_unlike_text(){
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
if ( bp_activity_remove_user_favorite( $_POST['id'] ) )
_e( '[custom like text]', 'buddypress' );
else
_e( '[custom unlike text]', 'buddypress' );
exit;
}
add_action( 'wp_ajax_activity_mark_fav', 'custom_like_text' );
add_action( 'wp_ajax_nopriv_activity_mark_fav', 'custom_like_text' );
add_action( 'wp_ajax_activity_mark_unfav', 'custom_unlike_text' );
add_action( 'wp_ajax_nopriv_activity_mark_unfav', 'custom_unlike_text' );
@godavid33 good to see you figured it out. Just a question: Considering members must be logged in to favorite an item, why do you need to use wp_ajax_nopriv_
?
@henrywright You don’t, but BP registers both of them so I figured I would follow suit so I didn’t accidentally break anything
@godavid33 sounds like a good idea. Better to be safe than sorry!