Making WordPress.org

Changeset 13518


Ignore:
Timestamp:
04/15/2024 03:34:01 AM (2 years ago)
Author:
dd32
Message:

Support Forums: Disable @moderator posting history archives to non-moderators.

Fixes #7584.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
2 edited

Legend:

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

    r12803 r13518  
    7979                add_filter( 'user_has_cap',                             array( $this, 'anon_moderator_user_has_cap' ), 10, 4 );
    8080                add_filter( 'wporg_notifications_pre_notify_matchers',  array( $this, 'notify_mod_of_at_mention' ), 10, 2 );
     81
     82                // Hide reply archives for the @moderator account.
     83                add_filter( 'bbp_get_user_replies_created', array( $this, 'filter_query_hide_moderator' ), 10, 2 );
     84                add_filter( 'bbp_get_user_topics_started',  array( $this, 'filter_query_hide_moderator' ), 10, 2 );
     85                add_filter( 'bbp_get_user_engagements',     array( $this, 'filter_query_hide_moderator' ), 10, 2 );
     86
     87                // Don't include @moderator activity on profiles.
     88                add_filter( 'wporg_profiles_wp_activity-is_forum_notifiable', array( $this, 'hide_moderator_profile_activity' ), 10, 2 );
    8189        }
    8290
     
    12511259                return $matchers;
    12521260        }
     1261
     1262        /**
     1263         * Disable activity queries for the moderator user, from non-moderators.
     1264         *
     1265         * @param bool $query   The user query.
     1266         * @param int  $user_id The user ID.
     1267         */
     1268        public function filter_query_hide_moderator( $query, $user_id ) {
     1269                if ( ! current_user_can( 'moderate' ) ) {
     1270                        // For the bbp_get_user_engagements filter
     1271                        if ( ! $user_id || ! is_numeric( $user_id ) ) {
     1272                                $user_id = bbp_get_displayed_user_id();
     1273                        }
     1274
     1275                        $moderator_user = get_user_by( 'slug', 'moderator' );
     1276                        if ( $moderator_user->ID === $user_id ) {
     1277                                return false;
     1278                        }
     1279                }
     1280
     1281                return $query;
     1282        }
     1283
     1284        /**
     1285         * Don't send @moderator actions to profiles.wordpress.org
     1286         *
     1287         * @param bool  $returnval Whether to send the profile activity or not.
     1288         * @param array $args      The data that will be sent to the activity API.
     1289         * @return bool $returnval
     1290         */
     1291        public function hide_moderator_profile_activity( $returnval, $args ) {
     1292                if ( 'moderator' == ( $args['user'] ?? '' ) ) {
     1293                        return false;
     1294                }
     1295
     1296                return $returnval;
     1297        }
    12531298}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-profiles-wp-activity-notifier/wporg-profiles-wp-activity-notifier.php

    r12128 r13518  
    331331                );
    332332
     333                if ( ! apply_filters( 'wporg_profiles_wp_activity-is_forum_notifiable', true, $args ) ) {
     334                        return;
     335                }
     336
    333337                Profiles\api( $args );
    334338        }
     
    396400                );
    397401
     402                if ( ! apply_filters( 'wporg_profiles_wp_activity-is_forum_notifiable', true, $args ) ) {
     403                        return;
     404                }
     405
    398406                Profiles\api( $args );
    399407        }
Note: See TracChangeset for help on using the changeset viewer.