Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with custom bbpress Like/Dislike plugin

  • @tkserver

    Participant

    I decided to program my own Like/Dislike plugin so I could customize it and tweak it for my exact needs. It’s working great in my custom threaded forum view for bbpress here:

    Ute Fan Board

    By using the hook bbp_theme_after_reply_admin_links I’m able to get the like buttons to show up in the bbpress topics and replies, but they’re all the parent topic. See photo below.

    bbpress like button

    Here’s one of my hooks:

    //adds the like buttons right of the time on forum posts in bbpress
    function tk_after_bbpress_content() {
         $custom_content_after_forum_title = tk_like_buttons();
        echo $custom_content_after_forum_title;
    }
    add_action( 'bbp_theme_after_reply_admin_links', 'tk_after_bbpress_content' );

    Hoping perhaps @robkk or @casiepa have some ideas? I can’t get the post id into the plugin for replies. Thanks!

Viewing 25 replies - 1 through 25 (of 27 total)
  • @tkserver

    Participant

    Wow I can’t believe it but I figured this out.

    Basically I wrote a function that looks for a result to the bbpress function bbp_reply_id();

    IF there’s a result, then replaced my $item_id (the actual post id such as $post->ID) with the id of the reply.

    That did the trick. One problem though is that the bbpress bbp_reply_id(); function echoes the number, so I had to clean the echo off like this:

    ob_start();
      $result = bbp_reply_id();
      ob_end_clean();

    @casiepa

    Moderator

    How about using bbp_get_reply_id ? I think that one is not echoing…

    Pascal.

    @netweb

    Keymaster

    How about using bbp_get_reply_id ? I think that one is not echoing…

    Correct 🙂

    Throughout much of bbPress this is true, more often than not if there is a function bbp_some_thing there will be a sister function bbp_get_some_thing, the functions with bbp_get_ will always just get the value for you to use, and the functions without it will echo the returned value.

    @netweb

    Keymaster

    p.s. I like what you’re doing where with your homepage and bbPress http://www.utehub.com 🙂

    @tkserver

    Participant

    Thanks @netweb for the comments. I worked a LONG time on that home page layout. I posted a rather lengthy commentary here describing how I got it to work, but sadly that post never appeared.

    So it does work if I clean off bbp_reply_id(); but I guess I could save a couple of lines of code by using bbp_get_reply_id();.

    @netweb

    Keymaster

    Oh, can’t seem to find it, not in the spam or moderation queue ¯\_(ツ)_/¯

    @tkserver

    Participant

    Probably user error… No biggie.

    @netweb

    Keymaster

    Cool, as its no biggie, I’ve added your site to our list here: https://bbpress.org/about/examples/ 🙂

    @tkserver

    Participant

    Oh cool that’s awesome. Thanks @netweb

    @robin-w

    Moderator

    Hey TK – love this layout – and hate that your commentary got lost – any chance you could give us some code and hints that would let others share this great work.

    I’m happy to help if stuff needs putting together eg i’m happy to write connecting sentences for non-experts if you do one liners for someone who knows what they are doing, and post stuff on the documentation part of bbpress etc.

    Would be a real shame for a great looking site not to become better used !!

    Feel free to contact me via my website if easier http://www.rewweb.co.uk

    @tkserver

    Participant

    Thanks @robin-w so perhaps we may be discussing two different things?

    This thread is related to my work on a custom like/dislike plugin for wordpress and bbpress. I did resolve the issue I described in the first post.

    I then integrated the like/dislike plugin into my custom bbpress “threaded view” layout, which is the home page of utehub.com.

    So just wondering which one you are talking about? I have a couple of threads here discussing the threaded view.

    @robin-w

    Moderator

    Hi @tkserver – yes it was the

    custom bbpress “threaded view” layout, which is the home page of utehub.com.

    that I was discussing – it looks really amazing !

    @robin-w

    Moderator

    So yes I’d love to see how you created that great layout, and maybe share the code to allow others to get the same effect.

    Are you up for that?

    @tkserver

    Participant

    Sure. It’s obviously very custom but I can explain how I did it. How would you like to do that?

    @robin-w

    Moderator

    Hey that’s great

    yes, maybe easier if you contact me via email
    then you can send any files that would be useful

    @tkserver

    Participant

    You have a lot of guts posting an email where spam bots can harvest it. I sent you an email. Now do me a favor and take your email off!!! See if you got the mail. Sometimes my mail gets caught in spam for some reason.

    @robin-w

    Moderator

    don’t normally post my address, and didn’t plan on leaving it there 🙂

    @robin-w

    Moderator

    and email rec’d – thanks !

    @tkserver

    Participant

    FYI this layout has morphed and improved quite a bit since the last post here.

    @robin-w

    Moderator

    just looked – continues to be an amazing site. My plans have changed somewhat – I may come back tom it again at a later stage, but I’m fully tied up in other stuff at the moment

    @tkserver

    Participant

    Thanks! Do you know much about WP_Query args and nested replies?!?!?! 🙂

    @mth75

    Participant

    I’m still trying to integrate the Buddypress favorite (like) system with BBPress, I think this would be the best way to go to integratie the 2 system. Not easy, did any of you guys look at this problem before?

    My site: http://www.starry-night.nl

    @mth75

    Participant

    Sadly, I can’t revert to a plugin or a own system (all due respect for your solution), my users liked to many activities already.

    @mth75

    Participant

    The trick is to relate the activity ID to the Post ID of the forum topic or reply. This code (used for liking (aka favouriting) ) blogpost works. I’m trying to rewrite it for bbpress

    In single.php:

    <?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;
    }

    @tkserver

    Participant

    Hey @mth75 is your last post in response to my threaded comment or the like function? Sorry about hijacking my own thread.

Viewing 25 replies - 1 through 25 (of 27 total)
  • You must be logged in to reply to this topic.
Skip to toolbar