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
This commit is contained in:
nacin 2010-10-21 15:05:10 +00:00
parent c46c3c4637
commit 02440f343c
1 changed files with 12 additions and 3 deletions

View File

@ -989,8 +989,6 @@ function register_post_type($post_type, $args = array()) {
* @return object object with all the capabilities as member variables * @return object object with all the capabilities as member variables
*/ */
function get_post_type_capabilities( $args ) { function get_post_type_capabilities( $args ) {
global $_post_type_meta_capabilities;
$default_capabilities = array( $default_capabilities = array(
// Meta capabilities are generally mapped to primitive capabilities depending on the context // 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: // (which would be the post being edited/deleted/read), instead of granted to users or roles:
@ -1003,6 +1001,7 @@ function get_post_type_capabilities( $args ) {
'publish_posts' => 'publish_' . $args->capability_type . 's', 'publish_posts' => 'publish_' . $args->capability_type . 's',
'read_private_posts' => 'read_private_' . $args->capability_type . 's', 'read_private_posts' => 'read_private_' . $args->capability_type . 's',
); );
// Primitive capabilities that are used within map_meta_cap(): // Primitive capabilities that are used within map_meta_cap():
if ( $args->map_meta_cap ) { if ( $args->map_meta_cap ) {
$default_capabilities_for_mapping = array( $default_capabilities_for_mapping = array(
@ -1016,9 +1015,19 @@ function get_post_type_capabilities( $args ) {
); );
$default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); $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 ); $capabilities = array_merge( $default_capabilities, $args->capabilities );
// Remember meta capabilities for future reference.
if ( $args->map_meta_cap ) if ( $args->map_meta_cap )
_post_type_meta_capabilities( $capabilities ); _post_type_meta_capabilities( $capabilities );
return (object) $capabilities; return (object) $capabilities;
} }