Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbp_new_reply action not firing when user replies to embedded thread


  • Ryan Giglio
    Participant

    @ryangiglio

    I’m working an educational website that produces video content and uses a BBPress forum for discussion rather than the native WordPress comments. Here’s how it works:

    I have a hook on wp_insert_post that creates a new BBPress topic when a new video post is created and saves this new topic_id to a _comment_topic_id meta field.

    In my single-video.php template where the video is displayed, I’m using the BBPress [bbp-single-topic id=$topic_id] shortcode to display the topic thread and reply form for people to post comments.

    All of this works great! I’m just having one problem – the “subscribe” feature of BBPress isn’t working when people post replies via the Video Single page. The reply is posted just fine, but subscribed users don’t receive a notification. If you’re not familiar – when a user subscribes to a thread, they receive an email whenever someone replies to the thread. This is still working fine when someone posts a reply via the actual Thread single page – it’s only a problem on the thread embedded via the shortcode on the Video single page.

    I’ve tried digging into the core and I got so far as to discover that the bbp_new_reply action isn’t firing – BBPress uses a function called bbp_notify_topic_subscribers hooked into bbp_new_reply to send the notifications and that function isn’t running at all when a reply is made via the Video single page.

    It seems that BBPress uses some hidden inputs to determine what actions to run after a reply has been submitted, but those seem to be included properly through the shortcode. These appear at the bottom of the Topic single form (that works properly);

        <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="422573">
        <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="0">
        <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply">
        <input type="hidden" id="_wpnonce" name="_wpnonce" value="83ea236cd1">
        <input type="hidden" name="_wp_http_referer" value="/forums/topic/SLUG/">

    And these appear at the bottom of the Video single form (that doesn’t)

        <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="422573">
        <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="0">
        <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply">
        <input type="hidden" id="_wpnonce" name="_wpnonce" value="83ea236cd1">
        <input type="hidden" name="_wp_http_referer" value="/videos/SLUG/">

    I’m at a loss for how to debug this issue further and could really use some help. BBPress has all kinds of page type/post type checks in the core that I’ve been ducking and weaving around, but this one has got me stumped. I suspect the problem is that SOMEWHERE it’s checking the post type of the current post, seeing it’s a video instead of a topic and bailing before the action runs, but I have no idea how or where to find that and how to patch around it.

    Thanks!

Viewing 1 replies (of 1 total)

  • Ryan Giglio
    Participant

    @ryangiglio

    Turns out every lead I was following was a red herring.

    I had another function hooked into wp_insert_post that was redirecting you back to the Video single page instead of sending you to the Thread single page if you posted your reply FROM the Video single page. It turns out that redirect was hitting and stopping execution before the bbp_new_reply actions were allowed allowed to fire.

    I changed that function to also hook into bbp_new_reply and changed its priority to 11 so it would run after the native actions. Working great!

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