Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BP_Blog_Post_Fav {
- var $activity_id;
- function init() {
- add_action( 'the_post', array( &$this, 'get_blog_post_activity_id' ) );
- }
- function get_blog_post_activity_id() {
- global $current_blog, $post;
- if( isset($post->ID) ) :
- $activity_id = bp_activity_get_activity_id( array(
- 'user_id' => $post->post_author,
- 'type' => 'new_blog_post',
- 'component' => 'blogs',
- 'item_id' => $current_blog->blog_id,
- 'secondary_item_id' => $post->ID) );
- $this->activity_id = $activity_id;
- if( !empty($this->activity_id) ) {
- add_filter( 'bp_get_activity_favorite_link', array( &$this, 'bp_get_activity_favorite_link' ) );
- add_filter( 'bp_get_activity_unfavorite_link', array( &$this, 'bp_get_activity_unfavorite_link' ) );
- add_filter( 'bp_get_activity_is_favorite', array( &$this, 'bp_get_activity_is_favorite' ) );
- }
- endif;
- }
- function bp_get_activity_favorite_link() {
- global $current_blog;
- if( $current_blog->blog_id != BP_ROOT_BLOG )
- switch_to_blog( BP_ROOT_BLOG );
- $nonce = wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $this->activity_id . '/' ), 'mark_favorite' );
- if( $current_blog->blog_id != BP_ROOT_BLOG )
- restore_current_blog();
- return $nonce;
- }
- function bp_get_activity_unfavorite_link() {
- global $current_blog;
- if( $current_blog->blog_id != BP_ROOT_BLOG )
- switch_to_blog( BP_ROOT_BLOG );
- $nonce = wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $this->activity_id . '/' ), 'unmark_favorite' );
- if( $current_blog->blog_id != BP_ROOT_BLOG )
- restore_current_blog();
- return $nonce;
- }
- function bp_get_activity_is_favorite() {
- global $bp;
- return in_array( $this->activity_id, (array)bp_activity_get_user_favorites($bp->loggedin_user->id) );
- }
- }
- $my_bp_favorite = new BP_Blog_Post_Fav();
- $my_bp_favorite->init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement