From 02440f343cce67ec0e20755b88cb929128fff30d Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 21 Oct 2010 15:05:10 +0000 Subject: [PATCH] Clean up get_post_type_capabilities. Don't bother with new capabilities for edit_others_posts and delete_others_posts if the post type does not support authors. git-svn-id: http://svn.automattic.com/wordpress/trunk@15892 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 03707f7b84..15528c8ef0 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -989,8 +989,6 @@ function register_post_type($post_type, $args = array()) { * @return object object with all the capabilities as member variables */ function get_post_type_capabilities( $args ) { - global $_post_type_meta_capabilities; - $default_capabilities = array( // Meta capabilities are generally mapped to primitive capabilities depending on the context // (which would be the post being edited/deleted/read), instead of granted to users or roles: @@ -1003,22 +1001,33 @@ function get_post_type_capabilities( $args ) { 'publish_posts' => 'publish_' . $args->capability_type . 's', 'read_private_posts' => 'read_private_' . $args->capability_type . 's', ); + // Primitive capabilities that are used within map_meta_cap(): if ( $args->map_meta_cap ) { $default_capabilities_for_mapping = array( 'read' => 'read', 'delete_posts' => 'delete_' . $args->capability_type . 's', 'delete_private_posts' => 'delete_private_' . $args->capability_type . 's', - 'delete_published_posts' => 'delete_published_' . $args->capability_type . 's', + 'delete_published_posts' => 'delete_published_' . $args->capability_type . 's', 'delete_others_posts' => 'delete_others_' . $args->capability_type . 's', 'edit_private_posts' => 'edit_private_' . $args->capability_type . 's', 'edit_published_posts' => 'edit_published_' . $args->capability_type . 's', ); $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); } + + if ( ! post_type_supports( $args->name, 'author' ) ) { + // While these may be checked in core, users/roles shouldn't need to be granted these. + $default_capabilities['edit_others_posts'] = $default_capabilities['edit_posts']; + $default_capabilities['delete_others_posts'] = $default_capabilities['delete_posts']; + } + $capabilities = array_merge( $default_capabilities, $args->capabilities ); + + // Remember meta capabilities for future reference. if ( $args->map_meta_cap ) _post_type_meta_capabilities( $capabilities ); + return (object) $capabilities; }