Skip to:
Content
Pages
Categories
Search
Top
Bottom

Need a little help with new bbPress plugin


  • Shmoo
    Participant

    @macpresss

    Okay as the title says I need a little help finishing a small bbPress plugin.

    Right now it checks each topic content against the bbPress topic-tags created from the back-end ( only those are assigned not empty tags ) and if there are matches between the tags and content it echo’s those matches found.

    The only deal-breaker here is how to add those matches found the $word Variable to each topic tags when you create a new topic or edit a topic fron the front-end.

    I believe you have to work with those two actions:

    
    add_action( 'bbp_new_topic',  'function_name', 10, 5 );
    add_action( 'bbp_edit_topic', 'function_name', 10, 5 );
    

    But how do you make the connection to the database table or how it’s called.

    This is the code I already made.
    http://pastebin.com/d7ZEifNb

    This Plugin was an idea because of this topic.

    Opinion: Tags in bbPress, do you like it or frustration to maintain?

    Some help from anybody who knows PHP and creating WP Plugins would be very cool.

    Thanks..

Viewing 8 replies - 1 through 8 (of 8 total)

  • Gautam Gupta
    Participant

    @gautamgupta

    Better hook it to bbp_new_reply_pre_set_terms here: https://bbpress.trac.wordpress.org/browser/trunk/includes/replies/functions.php#L371 and return the $words array after joining in the supplied $terms array. Similarly for topic.

    I’d also suggest to have this at the very beginning:

    if ( !bbp_allow_topic_tags() || !current_user_can( 'assign_topic_tags' ) )
    return $terms;

    Gautam Gupta
    Participant

    @gautamgupta

    Just realized that the ‘similar’ thing for topics doesn’t exist. Your method for topics is correct, and you’ll need something like this after you’ve the $words array:

    $words = array_unique( array_merge( $words, wp_get_post_terms( $topic_id, bbp_get_topic_tag_tax_id(), array( 'fields' => 'names' ) ) ) );
    if ( !empty( $words ) )
         wp_set_post_terms( $topic_id, $words, bbp_get_topic_tag_tax_id(), true );

    The top of the code should read as (to accept the $topic_id passed by do_action):

    add_action( 'bbp_new_topic',  'shmoo_auto_save_tags', 10, 1 );
    add_action( 'bbp_edit_topic', 'shmoo_auto_save_tags', 10, 1 );
    
    function shmoo_auto_save_tags( $topic_id ) {

    Again, untested, but should work in principle.


    Shmoo
    Participant

    @macpresss

    Thanks I appreciate your input but I can’t make it work..

    This is probably above my league. 🙁


    Gautam Gupta
    Participant

    @gautamgupta

    Paste the full code again?


    Shmoo
    Participant

    @macpresss

    This is what I have right now,

    http://pastebin.com/4FGpJpvn

    First I got undifined Variable for $topic_id so I added the $topic_id = 0; at the code, Zero stands for getting the topic ID from the loop ?


    Gautam Gupta
    Participant

    @gautamgupta


    Shmoo
    Participant

    @macpresss

    (y)

    Thank you so much it works..


    Gautam Gupta
    Participant

    @gautamgupta

    You’re welcome. And the explanation:

    First I got undifined Variable for $topic_id so I added the $topic_id = 0; at the code, Zero stands for getting the topic ID from the loop ?

    Where the bbp_new_topic hook is called, the line says:

    do_action( 'bbp_new_topic', $topic_id );

    It calls all the functions hooked to bbp_new_topic and also passes the $topic_id parameter, which in our case is:

    function shmoo_auto_save_tags( $topic_id ) {

    During this stage, I do not think we’re in the loop (I maybe wrong, I haven’t checked). The topic id internally would be something different at the point of insertion, that’s why in our function we’re now passing the variable to other functions:

    $bbp_topic_content = bbp_get_topic_content( $topic_id );

    On a side note, you had done $topic_id = 0; at the very beginning of the function. Due to that, whatever topic id was being passed was being disregarded and instead set to 0.

    More on actions and filters: https://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters

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