Making WordPress.org

Changeset 12767


Ignore:
Timestamp:
08/01/2023 09:56:57 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Moderation: Prevent self-moderation.

Fixes #7170.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/moderation.php

    r12735 r12767  
    5454        add_action( 'wporg_photos_moderation_email_sent', [ __CLASS__, 'sent_user_email' ] );
    5555        add_filter( 'wporg_photos_pre_upload_form',       [ __CLASS__, 'output_list_of_pending_submissions_for_user' ] );
     56
     57        // Disable moderating own posts.
     58        add_filter( 'user_has_cap',                       [ __CLASS__, 'disable_own_post_editing' ], 10, 4 );
    5659
    5760        // Add column to users table with count of photos moderated.
     
    191194                $caps = array_merge( (array) $photos_moderator_role->capabilities, (array) $caps );
    192195            }
     196        }
     197
     198        return $caps;
     199    }
     200
     201    /**
     202     * Prevents moderators from being able to edit or moderate their own photos.
     203     *
     204     * @param array    $caps Array of key/value pairs where keys represent a
     205     *                       capability name and boolean values represent whether
     206     *                       the user has that capability.
     207     * @param string[] $cap  Required primitive capabilities for requested capability.
     208     * @param array    $args {
     209     *     Arguments that accompany the requested capability check.
     210     *
     211     *     @type string    $0 Requested capability.
     212     *     @type int       $1 Concerned user ID.
     213     *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
     214     * }
     215     * @param WP_User  $user The user object.
     216     * @return array
     217     */
     218     public static function disable_own_post_editing( $caps, $cap, $args, $user ) {
     219        // Bail if not a relevant capability.
     220        if ( ! in_array( $cap[0], [ 'edit_photos', 'publish_photos' ] ) ) {
     221            return $caps;
     222        }
     223
     224        // Bail if no post context provided.
     225        if ( ! isset( $args[2] ) ) {
     226            return $caps;
     227        }
     228
     229        // Bail if user isn't a moderator.
     230        if ( ! user_can( $user->ID, 'photos_moderator' ) ) {
     231            return $caps;
     232        }
     233
     234        $post = get_post( $args[2] );
     235
     236        // Bail if not a photo post.
     237        if ( Registrations::get_post_type() !== $post->post_type ) {
     238            return $caps;
     239        }
     240
     241        // Disallow editing their own submission.
     242        if ( isset( $post->post_author ) && $post->post_author == $user->ID ) {
     243            $caps['edit_photos'] = false;
     244            $caps['publish_photos'] = false;
    193245        }
    194246
Note: See TracChangeset for help on using the changeset viewer.