+ case 'read_page':
+ $post = get_post( $args[0] );
+
+ if ( 'revision' == $post->post_type ) {
+ $post = get_post( $post->post_parent );
+ }
+
+ $post_type = get_post_type_object( $post->post_type );
+
+ if ( ! $post_type->map_meta_cap ) {
+ $caps[] = $post_type->cap->$cap;
+ // Prior to 3.1 we would re-call map_meta_cap here.
+ if ( 'read_post' == $cap )
+ $cap = $post_type->cap->$cap;
+ break;
+ }
+
+ $status_obj = get_post_status_object( $post->post_status );
+ if ( $status_obj->public ) {
+ $caps[] = $post_type->cap->read;
+ break;
+ }
+
+ if ( $post->post_author && $user_id == $post->post_author ) {
+ $caps[] = $post_type->cap->read;
+ } elseif ( $status_obj->private ) {
+ $caps[] = $post_type->cap->read_private_posts;
+ } else {
+ $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
+ }
+ break;
+ case 'publish_post':
+ $post = get_post( $args[0] );
+ $post_type = get_post_type_object( $post->post_type );
+
+ $caps[] = $post_type->cap->publish_posts;
+ break;
+ case 'edit_post_meta':
+ case 'delete_post_meta':
+ case 'add_post_meta':
+ $post = get_post( $args[0] );
+ $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
+
+ $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false;
+
+ if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) {
+ /**
+ * Filter whether the user is allowed to add post meta to a post.
+ *
+ * The dynamic portion of the hook name, $meta_key, refers to the
+ * meta key passed to map_meta_cap().
+ *
+ * @since 3.3.0
+ *
+ * @param bool $allowed Whether the user can add the post meta. Default false.
+ * @param string $meta_key The meta key.
+ * @param int $post_id Post ID.
+ * @param int $user_id User ID.
+ * @param string $cap Capability name.
+ * @param array $caps User capabilities.
+ */
+ $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps );
+ if ( ! $allowed )
+ $caps[] = $cap;
+ } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) {
+ $caps[] = $cap;
+ }
+ break;
+ case 'edit_comment':
+ $comment = get_comment( $args[0] );
+ if ( empty( $comment ) )
+ break;
+ $post = get_post( $comment->comment_post_ID );
+ $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
+ break;
+ case 'unfiltered_upload':
+ if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) )
+ $caps[] = $cap;
+ else
+ $caps[] = 'do_not_allow';
+ break;
+ case 'unfiltered_html' :
+ // Disallow unfiltered_html for all users, even admins and super admins.
+ if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML )
+ $caps[] = 'do_not_allow';
+ elseif ( is_multisite() && ! is_super_admin( $user_id ) )
+ $caps[] = 'do_not_allow';
+ else
+ $caps[] = $cap;
+ break;
+ case 'edit_files':
+ case 'edit_plugins':
+ case 'edit_themes':
+ // Disallow the file editors.
+ if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT )
+ $caps[] = 'do_not_allow';
+ elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
+ $caps[] = 'do_not_allow';
+ elseif ( is_multisite() && ! is_super_admin( $user_id ) )
+ $caps[] = 'do_not_allow';
+ else
+ $caps[] = $cap;
+ break;
+ case 'update_plugins':
+ case 'delete_plugins':
+ case 'install_plugins':
+ case 'upload_plugins':
+ case 'update_themes':
+ case 'delete_themes':
+ case 'install_themes':
+ case 'upload_themes':
+ case 'update_core':
+ // Disallow anything that creates, deletes, or updates core, plugin, or theme files.
+ // Files in uploads are excepted.
+ if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
+ $caps[] = 'do_not_allow';
+ } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
+ $caps[] = 'do_not_allow';
+ } elseif ( 'upload_themes' === $cap ) {
+ $caps[] = 'install_themes';
+ } elseif ( 'upload_plugins' === $cap ) {
+ $caps[] = 'install_plugins';
+ } else {
+ $caps[] = $cap;
+ }
+ break;
+ case 'activate_plugins':
+ $caps[] = $cap;
+ if ( is_multisite() ) {
+ // update_, install_, and delete_ are handled above with is_super_admin().
+ $menu_perms = get_site_option( 'menu_items', array() );
+ if ( empty( $menu_perms['plugins'] ) )
+ $caps[] = 'manage_network_plugins';
+ }
+ break;
+ case 'delete_user':
+ case 'delete_users':
+ // If multisite only super admins can delete users.
+ if ( is_multisite() && ! is_super_admin( $user_id ) )
+ $caps[] = 'do_not_allow';