Skip to:

Display the ‘New Reply Form’ for a specific Topic ID

  • parmaker


    1. When visitors come to a forum and click a topic from the topic index list, bbpress elegantly shows the lead topic and replies and Reply-to form on the topic page.
    2. I wanted to hide the reply form box, instead, put a link of pointing to a regualr wordpress page so that only visitor who wants might write a reply for that topic by clicking the link.
    3. So I copied a page from parent theme dir into the child theme dir, and named “forum_new_reply_form.php” and changed like :

      * Template Name: Forum New Reply Form<br>
      * @package WordPress<br>
      * @subpackage Twenty_Sixteen<br>
      * @since Twenty Sixteen 1.0<br>

      get header(); ?><br>

      < div id=”primary” class=”content-area”><br>
      < main id=”main” class=”site-main” role=”main”><br>
      < ?php <br>
      // Start the loop.<br>
      while ( have_posts() ) : the_post();<br>
      // nothing to do here <br>
      < ?php <br>
      global $wp_query;<br>
      if (isset($wp_query->query_vars[‘reply_to_this_topic’]))<br>
      { <br>
      < div class=”my-bbp-reply-form”><!– bbp-reply-form –><br>
      < ?php <br>
      $reply_shortcd = ‘[bbp-reply-form topic_id=”‘ . $wp_query->query_vars[‘reply_to_this_topic’] . ‘”]’;<br>
      echo do_shortcode($reply_shortcd);<br>
      ? ><br>
      < / div><!– bbp-reply-form –><br>
      < /main><!– .site-main –><br>

      < ?php get sidebar( ‘content-bottom’ ); ?><br>

      < / div><!– .content-area –><br>
      get sidebar()<br>
      get footer() <br>

    4. Go back to functions of childtheme, put this action

      function my_bbp_reply_form() {<br>
      if (!current_user_can(‘publish_replies’)){<br>
      $t = ‘< div class=”my-bbp-new-reply-form-link”>’; <br>
      $t .= ‘< a href=”http://kabum/write_reply_page/?reply_to_this_topic=&#8217; . bbp_get_topic_id() . ‘” title=”‘ . bbp_get_topic_title() . ‘”>’;<br>
      $t .= ‘< /a>< / div>’;<br>
      echo $t;<br>

    5. From content-single-topic.php, commented out

      bbp_get_template_part( ‘form’,’topic’);<br>

      so, i can see the lead topic and a link mentioed at 4), and replies if any.

    6. For debugging purpose, I copied form-reply.php into childtheme/bbpress, changed one line like this :

      // printf( __( ‘Reply To: %s’, ‘bbpress’ ), bbp_get_topic_title() );<br>
      echo ‘I am replying to ‘ . bbp_get_topic_title();<br>

      under < legend > of < fieldset > of that file.

    7. When I clicked the link which was added at 4), a reply form pops up without any topic and replies !! hurray !!!

      But disaster !!, <br> the page http : / /kabum/write_reply_page/?reply_to_this_topic=1234<br>
      shows <br>
      I am replying to “forum title” (the title of the regular page housing the template “Forum New Reply Form”)<br>

      It should have shown <br>
      I am replying to “topic title” (of topic id 1234)

    8. I learned that bbp_topic_id and bbp_reply_to are 0, that triggered fetching parent id of a topic.

      The page source of browser does even show html < input hidden name=bbp_topic_id value in the page.<br>
      The page of http://kabum/write_reply_page/?reply_to_this_topic=1234, exactly tells <br>
      reply_to_this_topic is 1234

    9. I changed topic_id of shorcode bbp-reply-form atts with reply_to before retrying.<br>

      Same thing happened.

    10. At the writing of this post, bbpress org documentation regarding to bbp-reply-form shortcode,<br>
      is not clearly saying about shortcode atts, but topic is [bbp-topic-form forum_id=$forum_id].
    11. in case topic creation, i did the similar way as mentioned above, works fine. no need to do with jquery stuff.
    12. bbpress outof box has action as h t tp://kabum/forums/topic/topic_title/#newpost, but my reply form page is
      h t tp://kabum/topic_title/?reply_to_this_topic=1234, i.e./forums/forum is sit in or not. In my reading of showrcode source, I can’t find any clue of hansdling atts reply_to hopfully i was wrong reading.


    Hopfully, looking forward to anyone’s help.

  • You must be logged in to reply to this topic.
Skip to toolbar