Created
July 8, 2012 22:33
-
-
Save quangbahoa/3073213 to your computer and use it in GitHub Desktop.
Buddypress Favorite Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## functions.php | |
/* | |
-------------------------------------------------------------------------------- | |
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' ) ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## single.php in the loop | |
<?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;?> |
How can I get rid of the bullet point that shows next to the Favorite link this outputs and how can I get it to not have to refresh the webpage to favorite a post?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When i click it, it saves as favourite but it shows 'Remove from Fav..' in all posts...