Skip to:
Content
Pages
Categories
Search
Top
Bottom

Integrating Buddypress favorite system (aka like system) with BBPress


  • puniler
    Participant

    @puniler

    Hi all,

    I’m trying to integrate the BuddyPress favorite (aka like system) system with BBPress.

    But I can not implement ajax and the page will be reloaded.

    How do I write it?

    ▼【functions.php】

    function my_bp_activity_is_favorite($activity_id) { 
      global $bp, $activities_template;  
      return apply_filters( 'bp_get_activity_is_favorite', in_array( $activity_id, (array)$activities_template->my_favs ) );  
    }  
    function my_bp_activity_favorite_link($activity_id) {  
      global $activities_template;  
      echo apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $activity_id . '/' ), 'mark_favorite' ) );  
    }  
    function my_bp_activity_unfavorite_link($activity_id) { 
      global $activities_template;  
      echo apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $activity_id . '/' ), 'unmark_favorite' ) );  
    }  

    ▼【bbPress/templates/default/bbpress/loop-single.php】

    <div id="post-<?php bbp_reply_id(); ?>" class="bbp-reply-header">
    
      <!--omission-->
    
        <div class="favorite-wrap">
            <?php $activity_id = get_post_meta( bbp_get_reply_id( $reply_id ), '_bbp_activity_id', true ); ?>  
            <?php if ( is_user_logged_in() ) : ?>  
                <?php bp_has_activities(); ?>   
                <?php if ( !my_bp_activity_is_favorite($activity_id) ) : ?>  
                    <a href="<?php my_bp_activity_favorite_link($activity_id) ?>" 
                    class="button fav bp-secondary-action bp-tooltip" data-bp-tooltip="add" aria-pressed="false">
                    <span class="bp-screen-reader-text">add</span>
                    </a> 
                <?php else : ?>  
                    <a href="<?php my_bp_activity_unfavorite_link($activity_id) ?>" 
                    class="button unfav bp-secondary-action bp-tooltip" data-bp-tooltip="remove" aria-pressed="false">
                    <span class="bp-screen-reader-text">remove</span>
                    </a>
                <?php endif; ?>  
            <?php endif;?>  
        </div>
    
      <!--omission-->
    
    </div><!-- #post-<?php bbp_reply_id(); ?> -->

    Help for figuring this one out is appreciated.
    Best regards

  • You must be logged in to reply to this topic.
Skip to toolbar