Skip to:
Content
Pages
Categories
Search
Top
Bottom

How would I filter the text from the favorite button?


  • godavid33
    Participant

    @godavid33

    I need to change the text returned by the ajax function that is triggered when you click the favorite or unfavorite button. Particularly, I just need the function name. I can probably take it from there, though if you want to just give me the whole function I wouldn’t complain 🙂

    bp 2.0 wp 3.9

Viewing 7 replies - 1 through 7 (of 7 total)

  • Henry Wright
    Moderator

    @henrywright

    Take a look at bp_dtheme_mark_activity_favorite and bp_dtheme_unmark_activity_favorite in bp-themes/bp-default/_inc/ajax.php


    godavid33
    Participant

    @godavid33

    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 🙁


    godavid33
    Participant

    @godavid33

    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.


    godavid33
    Participant

    @godavid33

    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' );
    

    Henry Wright
    Moderator

    @henrywright

    @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_?


    godavid33
    Participant

    @godavid33

    @henrywright You don’t, but BP registers both of them so I figured I would follow suit so I didn’t accidentally break anything


    Henry Wright
    Moderator

    @henrywright

    @godavid33 sounds like a good idea. Better to be safe than sorry!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How would I filter the text from the favorite button?’ is closed to new replies.
Skip to toolbar