Making WordPress.org

Changeset 5632


Ignore:
Timestamp:
07/08/2017 11:09:18 AM (9 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Disallow moderators and keymasters to edit admins and super admins, unless they have the same role.

See #1985.

File:
1 edited

Legend:

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

    r5631 r5632  
    128128         * an Administrator role on the site.
    129129         *
    130          * @param array  $caps    User's actual capabilities.
    131          * @param string $cap     Capability name.
    132          * @param int    $user_id Current user ID.
    133          * @param array  $args    Capability context, typically the object ID.
     130         * @param array  $caps            User's actual capabilities.
     131         * @param string $cap             Capability name.
     132         * @param int    $current_user_id Current user ID.
     133         * @param array  $args            Capability context, typically the object ID.
    134134         * @return array Filtered capabilities.
    135135         */
    136         function map_meta_caps( $caps, $cap, $user_id, $args ) {
     136        function map_meta_caps( $caps, $cap, $current_user_id, $args ) {
    137137                switch ( $cap ) {
    138138                        case 'promote_user':
    139139                        case 'promote_users':
    140                                 // Only keymasters can promote users.
    141                                 $caps = array( 'keep_gate' );
    142                                 break;
    143 
    144140                        case 'edit_user':
    145141                        case 'edit_users':
    146142                                // Bail before "User Role" section is displayed.
    147143                                // See https://bbpress.trac.wordpress.org/ticket/3126
    148                                 if ( did_action( 'bbp_user_edit_after_account' ) && ! bbp_is_user_keymaster( $user_id ) ) {
     144                                if ( did_action( 'bbp_user_edit_after_account' ) && ! bbp_is_user_keymaster( $current_user_id ) ) {
    149145                                        return $caps;
    150146                                }
    151147
    152148                                // Get the user ID.
    153                                 $_user_id = ! empty( $args[0] )
     149                                $user_id_to_check = ! empty( $args[0] )
    154150                                        ? (int) $args[0]
    155151                                        : bbp_get_displayed_user_id();
    156152
    157153                                // Users can always edit themselves, so only map for others.
    158                                 if ( ! empty( $_user_id ) && ( $_user_id !== $user_id ) ) {
    159 
     154                                if ( ! empty( $user_id_to_check ) && ( $user_id_to_check !== $current_user_id ) ) {
    160155                                        // Moderators cannot edit keymasters.
    161                                         if ( ! bbp_is_user_keymaster( $_user_id ) ) {
     156                                        if ( bbp_is_user_keymaster( $user_id_to_check ) ) {
     157                                                return $caps;
     158                                        }
     159
     160                                        // Moderators and keymasters cannot edit admins or super admins, unless they have the same role.
     161                                        if ( user_can( $user_id_to_check, 'manage_options' ) || is_super_admin( $user_id_to_check ) ) {
     162                                                return $caps;
     163                                        }
     164
     165                                        if ( 'promote_user' === $cap || 'promote_users' === $cap ) {
     166                                                // Only keymasters can promote users.
     167                                                $caps = array( 'keep_gate' );
     168                                        } else {
    162169                                                $caps = array( 'moderate' );
    163170                                        }
Note: See TracChangeset for help on using the changeset viewer.