Making WordPress.org

Changeset 11978


Ignore:
Timestamp:
07/19/2022 06:01:45 AM (21 months ago)
Author:
dd32
Message:

Support Forums: Attempt to send notifications for new topics/replies when it's caught within the moderation or spam queue.

bbPress subscription notifications (and WordPress.org's) are hooked to the bbp_new_topic action, however they also verify that the thread is public before notifying.
Unfortunately, bbPress does not trigger the notifications upon the thread being unspammed/approved, and neither do the WordPress.org notifications.

This fixes this condition by triggering the "new topic created" hook after a topic/reply is unspammed/approved for the first time, causing the subscriptions codes to run as if it's a brand-new thread.

This should fix plugin subscription notifications not being sent to some plugin authors, and topic authors who are unaware of a reply because the responding author was caught in a moderation queue.

It's worth noting that replies still only trigger notifications (matchers, topic/forum subscriptions, @mention's, etc) if the topic is public AND the reply will be public.
If a reply is added to a pending topic, notifications for that reply will NOT be re-sent, unless the reply was also in a pending state unrelated to the topic and is then approved after the topic is.

See #3674.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-emails.php

    r11563 r11978  
    55 * Support Forum Email modifications.
    66 *
    7  * This filters outgoing bbPress emails to 'unroll' subscription emails from a set of BCC's to individual emails.
     7 * This provides some overrides to work around limitations / bugs in bbPress related to email.
     8 *  1. Filters outgoing bbPress emails to 'unroll' subscription emails from a set of BCC's to individual emails.
     9 *  2. Sends subscription emails upon approval for topics/replies.
    810 */
    911class Emails {
     12    const SUBSCRIPTIONS_TRIGGER_KEY = '_wporg_trigger_notifications_on_approve';
    1013
    1114    public function __construct() {
     
    1720        add_action( 'bbp_pre_notify_subscribers',  [ $this, 'start_unroll' ] );
    1821        add_action( 'bbp_post_notify_subscribers', [ $this, 'stop_unroll' ] );
    19     }
     22
     23        // Subscriptions - Send subscriptions after approval/unspam.
     24        add_action( 'bbp_new_topic', [ $this, 'bbp_new_topic' ], 20, 2 );
     25        add_action( 'bbp_new_reply', [ $this, 'bbp_new_reply' ], 20, 3 );
     26
     27        add_action( 'bbp_unspammed_topic', [ $this, 'maybe_trigger_bbp_new_topic' ], 10, 1 );
     28        add_action( 'bbp_approved_topic',  [ $this, 'maybe_trigger_bbp_new_topic' ], 10, 1 );
     29        //add_action( 'bbp_untrashed_topic', [ $this, 'maybe_trigger_bbp_new_topic' ], 10, 1 );
     30
     31        add_action( 'bbp_unspammed_reply', [ $this, 'maybe_trigger_bbp_new_reply' ], 10, 1 );
     32        add_action( 'bbp_approved_reply',  [ $this, 'maybe_trigger_bbp_new_reply' ], 10, 1 );
     33        //add_action( 'bbp_untrashed_reply', [ $this, 'maybe_trigger_bbp_new_reply' ], 10, 1 );
     34    }
     35
     36    // --- Email BCC unrolling...
    2037
    2138    /**
     
    108125        return $filter_return;
    109126    }
     127
     128    // --- bbPress not sending notifications if it's caught in spam/moderation queue
     129
     130    /**
     131     * Add postmeta to new unpublished replies, to send notifications once it's published.
     132     */
     133    public function bbp_new_reply( $reply_id, $topic_id, $forum_id ) {
     134        if ( bbp_is_reply_published( $reply_id ) && bbp_is_topic_public( $topic_id ) ) {
     135            return;
     136        }
     137
     138        add_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY, 1 );
     139    }
     140
     141    /**
     142     * Add postmeta to new unpublished topics, to send notifications once it's published.
     143     */
     144    public function bbp_new_topic( $topic_id, $forum_id ) {
     145        if ( bbp_is_topic_public( $topic_id ) ) {
     146            return;
     147        }
     148
     149        add_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY, 1 );
     150    }
     151
     152    /**
     153     * Send forum subscriptions for a previously-unpublished topic.
     154     */
     155    public function maybe_trigger_bbp_new_topic( $topic_id ) {
     156        if ( ! get_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY, true) ) {
     157            return;
     158        }
     159
     160        if ( ! bbp_is_topic_public( $topic_id ) ) {
     161            return;
     162        }
     163
     164        $forum_id     = bbp_get_topic_forum_id( $topic_id );
     165        $topic_author = bbp_get_reply_author_id( $reply_id );
     166
     167        // Remove the bbPress topic update handler
     168        remove_action( 'bbp_new_topic', 'bbp_update_topic' );
     169
     170        // Call the bbp_new_topic action..
     171        do_action( 'bbp_new_topic', $topic_id, $forum_id, array(), $topic_author );
     172
     173        add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 ); // bbPress requests 5, but calls it with 4..
     174
     175        delete_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY );
     176    }
     177
     178    /**
     179     * Send topic subscriptions for a previously-unpublished topic.
     180     */
     181    public function maybe_trigger_bbp_new_reply( $reply_id ) {
     182        if ( ! get_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY, true ) ) {
     183            return;
     184        }
     185
     186        $topic_id     = bbp_get_reply_topic_id( $reply_id );
     187        $forum_id     = bbp_get_topic_forum_id( $topic_id );
     188        $reply_author = bbp_get_reply_author_id( $reply_id );
     189
     190        if ( ! bbp_is_reply_published( $reply_id ) || ! bbp_is_topic_public( $topic_id ) ) {
     191            return;
     192        }
     193
     194        remove_action( 'bbp_new_reply', 'bbp_update_reply' );
     195
     196        do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, array(), $reply_author, false, false );
     197
     198        add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 7 );
     199
     200        delete_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY );
     201    }
     202
    110203}
Note: See TracChangeset for help on using the changeset viewer.