Making WordPress.org

Changeset 12803


Ignore:
Timestamp:
08/03/2023 04:03:14 AM (3 years ago)
Author:
dd32
Message:

Support Forums: When @moderator is mentioned in a bbPress reply, notify any moderator who has interacted with that topic.

See #6839.

File:
1 edited

Legend:

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

    r12802 r12803  
    7878                add_action( 'bbp_theme_before_reply_author_details',    array( $this, 'show_anon_mod_name' ) );
    7979                add_filter( 'user_has_cap',                             array( $this, 'anon_moderator_user_has_cap' ), 10, 4 );
     80                add_filter( 'wporg_notifications_pre_notify_matchers',  array( $this, 'notify_mod_of_at_mention' ), 10, 2 );
    8081        }
    8182
     
    11901191         *
    11911192         * This keeps the moderator account as a low-access account, while also showing the replies
    1192          * with a moderator badge. This should probably ideally be a filter on the badges.
     1193         * with a moderator badge, and bypassing moderation.
    11931194         */
    11941195        public function anon_moderator_user_has_cap( $allcaps, $caps, $args, $user ) {
     
    12041205                return $allcaps;
    12051206        }
     1207
     1208        /**
     1209         * When a @moderator mention is used in a reply, notify the
     1210         * moderators who have interacted with that thread.
     1211         *
     1212         * As it's possible for multiple moderators to be involved in a thread
     1213         * the notification is sent to all who have interacted with it.
     1214         *
     1215         * This filter is within the wporg-notifications plugin.
     1216         */
     1217        public function notify_mod_of_at_mention( $matchers, $data ) {
     1218                if (
     1219                        empty( $matchers['moderator']->type ) ||
     1220                        'username' != $matchers['moderator']->type ||
     1221                        'forum_topic_reply' != $data['type']
     1222                ) {
     1223                        return $matchers;
     1224                }
     1225
     1226                // Get all moderators who have interacted with this thread.             
     1227                $mod_replies = (array) get_posts( [
     1228                        'post_parent'    => $data['topic_id'],
     1229                        'post_type'      => bbp_get_reply_post_type(),
     1230                        'author'         => get_user_by( 'slug', 'moderator' )->ID,
     1231                        'fields'         => 'ids',
     1232                        'posts_per_page' => -1,
     1233                        'order'          => 'ASC'
     1234                ] );
     1235
     1236                $moderators = [];
     1237                foreach ( $mod_replies as $reply_id ) {
     1238                        $moderators[] = get_post_meta( $reply_id, self::MODERATOR_REPLY_AUTHOR, true );
     1239                }
     1240
     1241                foreach ( array_unique( $moderators ) as $mod_id ) {
     1242                        $moderator = get_user_by( 'id', $mod_id );
     1243                        if ( ! $moderator || isset( $matchers[ $moderator->user_nicename ] ) ) {
     1244                                continue;
     1245                        }
     1246
     1247                        $matchers[ $moderator->user_nicename ]                    = $matchers['moderator'];
     1248                        $matchers[ $moderator->user_nicename ]->notification_name = "@moderator response";
     1249                }
     1250
     1251                return $matchers;
     1252        }
    12061253}
Note: See TracChangeset for help on using the changeset viewer.