Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with bbpress API, a first plugin…


  • jezza101
    Participant

    @jezza101

    Hi, I’m struggling a bit to get started with bbpress plugin dev, I’ve managed to write plugins for WP in the past thanks to the WP codex. Looking at other threads I see the advice is to look at the WP documentation or look at examples – I’ve tried both and getting a bit stuck. If anyone has some time to help me get hooked into the API it would be much appreciated – after that I should be able to start creating some cool stuff!

    So my first experiment is to try and update a post within a topic. Looking at the append signature plugin I can see they use the bbp_get_topic_content filter. If I were updating “the_content” in WP I would do something like this:

    function bbp_topic_content_append_text( $content = '') { 
                $content = $content . 'SOME_TEST_TEXT';
    
                        return $content;
        }
    
        add_filter( 'bbp_get_topic_content', 'bbp_topic_content_append_text');
    

    But this doesn’t do anything when I load a topic? Can anyone point me in the right direction? Thanks 🙂

    • This topic was modified 11 years, 7 months ago by jezza101.
    • This topic was modified 11 years, 7 months ago by jezza101.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Are you trying to append to the content of the main topic content (the lead), or to all replies within a topic?


    jezza101
    Participant

    @jezza101

    As a first goal I would like to be able to alter the content of each reply shown on the topic page. So actually that would include the lead topic post (in bbpress terms the OP is the topic and subsequent posts are the replies, yeah?)

    I think I would also need to know the reply’s ID and whether it was the first reply. If I can get a basic template for that I reckon I can get going with the rest 🙂

    There are two plugins I built for e107 and I would like to have a go at bbpress 2 versions. One is a ‘Thanks’ plugin, so I’d need to eg add a “thank this post” button to each post, and show a user’s ‘thanks’ count next to their name.

    The other is an adense plugin which popped an ad unit inbetween the OP and first reply.

    Many Thanks.

    • This reply was modified 11 years, 6 months ago by jezza101.

    Here’s a really basic way of how you can do it: https://gist.github.com/3788409


    jezza101
    Participant

    @jezza101

    Thanks Pip. Starting to make some progress. I’ve been playing around with some other filters and beginning to explore, I can see how to manipulate various components of a post.

    But I’ve hit a brick wall, do you know how to insert something between the first and second post for example?

    My goal is to inject a “dummy post” which had the same template as a normal post but contained my own message.

    Many thanks.

    I would suggest you simply append it to the content of the lead topic.


    jezza101
    Participant

    @jezza101

    OK, so to do that I would have to close the post myself, which looks like I just have to add two x divs

     Div   <!-- .bbp-reply-content -->
    

    Div

    But it looks like HTML filters are being applied still – ah, is this a case of ordering things so that my filter comes right at the end, ie after the HTML filter?

    ..ah a quick test and, yes, this seems to work.

    $content=$content.'TEST1(/div)(/div)IS THIS BETWEEN POSTS? YES!(div)(div)';
    

    Ah apologies, the forum filter has filtered out the DIVs above.. putting them back in with curly brackets.

    Excellent. Looks like I need to put some thought into how to make it look good but I think I can work on that! One last question then (sorry, and thanks for your help!), how do I pick out the first post?

    • This reply was modified 11 years, 6 months ago by jezza101.

    Off the top of my head I’m not sure, but tinker with it a little and report back. I’ll be traveling for a day or two, but I can try tinkering with it when I get back.


    jezza101
    Participant

    @jezza101

    Thanks loads, I’m definitely on my way now. If I can just identify the first post then I’ve got everything I need.

    I guess I could just set a global flag once we’ve done the first loop to say don’t process my function again – but that doesn’t seem particularly elegant!

    Cheers, will definitely pop a credit / link in when I get this out.

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