Favoriting Blog Posts — Code Inside worked with 1.2.x, not so much with 1.5.x
-
So I’ve finally decided to take the plunge and try and update my BP community at Gamefilter.net to 1.5.x, figuring the dust has pretty well settled by now. Working on my localhost install, so the live site is still working fine. The upgrade has gone pretty well, for the most part, except for one thing.
It’s all a little complicated, but I’m hoping it’s something that someone more skilled with wrangling BP code than me can just eyeball it and say ‘There’s your problem’!
So I’m using both a heavily customized version of the old BP-Like plugin to provide a ‘Thanks’ functionality for people’s activity, including posting to the main blog. This is counted — thanks given and received — on user profiles.
Separate to that is BP favoriting (which I’ve renamed to ‘Bookmark’), which lets people, yeah, save stuff as favorites, that they can go back to later. I extended BP favoriting to blog posts with the following functions.php code:
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();
and I build a favorite link on a blog post (remember, it’s called ‘bookmark’ on the live site, in case you want to look at it (but it’s only visible for logged-in users, so)) like so
<a class="button fav bp-secondary-action" href="" title=""></a>
That builds a link that looks like this (on localhost)
http://localhost/gamefilter/activity/favorite/837/?_wpnonce=66c4831cef
This worked swimmingly on my current 1.2 install on the live site, but now, on my local testbed, clicking the link doesn’t do any ajax, and just takes me to the search results page, with no results found.
I guess something obvious has changed since 1.2, but I’ve spent all day hammering away and can’t seem to figure it out. If anybody has any ideas, I’d be very grateful. Thanks!
- The topic ‘Favoriting Blog Posts — Code Inside worked with 1.2.x, not so much with 1.5.x’ is closed to new replies.