Making WordPress.org

Changeset 12707


Ignore:
Timestamp:
07/03/2023 08:05:26 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Admin: Prevent moderators from accessing media library.

See #7119.

File:
1 edited

Legend:

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

    r12706 r12707  
    5858        // Modify admin menu links for photo posts.
    5959        add_action( 'admin_menu',                              [ __CLASS__, 'modify_admin_menu_links' ] );
     60
     61        // Restrict Media Library access.
     62        add_action( 'admin_init',                              [ __CLASS__, 'restrict_media_library_access' ] );
     63        add_action( 'admin_menu',                              [ __CLASS__, 'disable_media_library' ] );
    6064
    6165        // Navigate to next post after moderation.
     
    10341038
    10351039    /**
     1040     * Restricts direct access to the Media Library by moderators.
     1041     */
     1042    public static function restrict_media_library_access() {
     1043        global $pagenow;
     1044        if (
     1045            'upload.php' === $pagenow
     1046        &&
     1047            ! current_user_can( get_post_type_object( 'post' )->cap->create_posts )
     1048        ) {
     1049            wp_die( __( 'Sorry, you are not allowed to access the media library.', 'wporg-photos' ) );
     1050        }
     1051    }
     1052
     1053    /**
     1054     * Removes "Media Library" from the admin menu for moderators.
     1055     */
     1056    public static function disable_media_library() {
     1057        if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
     1058            remove_menu_page( 'upload.php' );
     1059        }
     1060    }
     1061
     1062    /**
    10361063     * Modifies admin menu links for photo posts.
    10371064     *
Note: See TracChangeset for help on using the changeset viewer.