Integrating Buddypress favorite system (aka like system) with BBPress
-
Hi all,
I’m trying to integrate the BuddyPress favorite (aka like system) system with BBPress.
On my site: http://www.starry-night.nl I use the BuddyPress Activity page as homepage, this means that forum topics and replies are
shown on the activity wall, and can be liked.For easy navigation I made a custom “comment” button which links to the BBPress topic or reply. BBPress activity items (topics or replies)
can be liked.Going to a forum topic of replies of course doesn’t show any likes in the BBPress topic and replies.
Integrating the BuddyPress favorite system with BBPress is at least in my mind the cleanest way and from a functionality point of view, the way
to go.On the BuddyPress forum I found the following code (below) which implements the BuddyPress favorite button in blogpost (and this works), so a rewrite
should be possible to make this work for BBPress.In single.php for blogpost and in the future in the loop-single-reply.php for BBPress.
<?php echo get_fav_or_unfav_button_for_post( $post ); ?>
In function.php:
/ Buddypress favorites function get_fav_or_unfav_button_for_post( $post ) { global $bp, $activities_template; // user is not logged ? Show nothing. if ( ! is_user_logged_in() ) { return ''; } $activity_id = bp_activity_get_activity_id( array( 'user_id' => $post->post_author, 'type' => 'new_blog_post', 'component' => 'blogs', 'item_id' => 1, 'secondary_item_id' => $post->ID ) ); if ( ! $activity_id ) { return ''; } bp_has_activities(); // update $activities_template of user's fav $old_value = false; if ( isset( $activities_template->activity->id ) ) { $old_value = $activities_template->activity->id; $activities_template->activity->id = $activity_id; } else { $activities_template->activity = (object) array( 'id' => $activity_id ); } // building the template $code = ''; $code .= '<div class="activity-meta">'."\n"; if ( ! bp_get_activity_is_favorite() ) { // if not favorited, add a fav button $code .= ' <a href="'.bp_get_activity_favorite_link( ).'" class="button fav bp-secondary-action" title="'.__( 'Like', 'buddypress' ).'">'.__( 'Like', 'buddyboss' ).'</a>'."\n"; } else { // if already favorited, a button to unfav $code .= ' <a href="'.bp_get_activity_unfavorite_link( ).'" class="button unfav bp-secondary-action" title="'.__( 'Unlike', 'buddypress' ).'">'.__( 'Unlike', 'buddyboss' ).'</a>'."\n"; // bonus button to show user's all favs $code .= ' <a href="'.bp_loggedin_user_domain() . 'activity/favorites/" class="button unfav bp-secondary-action">'.__( 'My Likes', 'buddyboss' ).'</a>'."\n"; } // closing .activity-meta $code .= '</div>'."\n"; if ( false !== $old_value ) { $activities_template->activity->id = $old_value; } else { $activities_template->activity = null; } return $code; }
I’m having problems with rewriting the array for bbpress:
$activity_id = bp_activity_get_activity_id( array( 'user_id' => $post->post_author, 'type' => 'new_blog_post', 'component' => 'blogs', 'item_id' => 1, 'secondary_item_id' => $post->ID ) );
Help for figuring this one out is appreciated.
Best regards,
Marc
- You must be logged in to reply to this topic.