functions.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
--------------------------------------------------------------------------------
Favorites button applied to individual posts
Based on: http://www.dnxpert.com/2010/06/11/mark-blog-post-as-favorite-in-buddypress/
--------------------------------------------------------------------------------
*/

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

single.php in the loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php global $bp;
$activity_id = bp_activity_get_activity_id( array(
'user_id' => $post->author_id,
'type' => 'new_blog_post',
'component' => 'blogs',
'item_id' => 1,
'secondary_item_id' => $post->ID
) );
?>

<?php if ( is_user_logged_in() ) : ?>
<div role="main" class="activity">
	<ul class="post-activity" id="activity-stream">
		<li id="activity-<?php echo $activity_id; ?>">
			<div>
				<div>
					<?php bp_has_activities();
					if ( !my_bp_activity_is_favorite($activity_id) ) : ?>
					<a href="<?php my_bp_activity_favorite_link($activity_id) ?>" class="button bp-secondary-action fav" title="<?php _e( 'Mark as Favorite', 'buddypress' ) ?>"><?php _e( 'Favorite', 'buddypress' ) ?></a>
					<?php else : ?>
					<a href="<?php my_bp_activity_unfavorite_link($activity_id) ?>" class="button bp-secondary-action unfav" title="<?php _e( 'Remove Favorite', 'buddypress' ) ?>"><?php _e( 'Remove Favorite', 'buddypress' ) ?></a>
					<?php endif; ?>
				</div>
			</div>
		</li>
	</ul>
</div>
<?php endif;?>