diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 782d8d8b4e..f770c49884 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -142,7 +142,7 @@ if ( post_type_supports($post_type, 'comments') ) if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') ) add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core'); -if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) ) +if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core'); if ( post_type_supports($post_type, 'author') ) { @@ -221,7 +221,7 @@ $shortlink = wp_get_shortlink($post->ID, 'post'); if ( !empty($shortlink) ) $sample_permalink_html .= '' . __('Get Shortlink') . ''; -if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) ) { ?> +if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status ) diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 2bfc09d2a7..1be0be967d 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -19,7 +19,7 @@ $_GET['post_type'] = $post_type; $post_type_object = get_post_type_object($post_type); -if ( !current_user_can($post_type_object->edit_type_cap) ) +if ( !current_user_can($post_type_object->cap->edit_posts) ) wp_die(__('Cheatin’ uh?')); // Back-compat for viewing comments of an entry @@ -73,7 +73,7 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet case 'trash': $trashed = 0; foreach( (array) $post_ids as $post_id ) { - if ( !current_user_can($post_type_object->delete_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to move this item to the Trash.') ); if ( !wp_trash_post($post_id) ) @@ -86,7 +86,7 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet case 'untrash': $untrashed = 0; foreach( (array) $post_ids as $post_id ) { - if ( !current_user_can($post_type_object->delete_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to restore this item from the Trash.') ); if ( !wp_untrash_post($post_id) ) @@ -101,7 +101,7 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet foreach( (array) $post_ids as $post_id ) { $post_del = & get_post($post_id); - if ( !current_user_can($post_type_object->delete_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to delete this item.') ); if ( $post_del->post_type == 'attachment' ) { @@ -140,7 +140,7 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet wp_enqueue_script('inline-edit-post'); $user_posts = false; -if ( !current_user_can($post_type_object->edit_others_cap) ) { +if ( !current_user_can($post_type_object->cap->edit_other_posts) ) { $user_posts_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(1) FROM $wpdb->posts WHERE post_type = '%s' AND post_status NOT IN ('trash', 'auto-draft') AND post_author = %d", $post_type, $current_user->ID) ); $user_posts = true; if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) ) @@ -345,7 +345,7 @@ do_action('restrict_manage_posts'); edit_others_cap) ) { ?> +if ( $is_trash && current_user_can($post_type_object->cap->edit_other_posts) ) { ?>
@@ -396,7 +396,7 @@ if ( $page_links ) -edit_others_cap) ) { ?> +cap->edit_other_posts) ) { ?>
diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 63e8e7e910..0459cd6d1e 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -14,7 +14,7 @@ function post_submit_meta_box($post) { $post_type = $post->post_type; $post_type_object = get_post_type_object($post_type); - $can_publish = current_user_can($post_type_object->publish_cap); + $can_publish = current_user_can($post_type_object->cap->publish_posts); ?>
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index a03d998f2f..db3ee44815 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -46,7 +46,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { $ptype = get_post_type_object( $post_data['post_type'] ); if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) { - if ( !current_user_can( $ptype->edit_others_cap ) ) { + if ( !current_user_can( $ptype->cap->edit_other_posts ) ) { if ( 'page' == $post_data['post_type'] ) { return new WP_Error( 'edit_others_pages', $update ? __( 'You are not allowed to edit pages as this user.' ) : @@ -81,7 +81,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published. // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. - if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->publish_cap )) ) + if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) ) if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) ) $post_data['post_status'] = 'pending'; @@ -138,7 +138,7 @@ function edit_post( $post_data = null ) { $post_ID = (int) $post_data['post_ID']; $ptype = get_post_type_object($post_data['post_type']); - if ( !current_user_can( $ptype->edit_cap, $post_ID ) ) { + if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) { if ( 'page' == $post_data['post_type'] ) wp_die( __('You are not allowed to edit this page.' )); else @@ -237,7 +237,7 @@ function bulk_edit_posts( $post_data = null ) { else $ptype = get_post_type_object('post'); - if ( !current_user_can( $ptype->edit_type_cap ) ) { + if ( !current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' == $ptype->name ) wp_die( __('You are not allowed to edit pages.')); else @@ -494,7 +494,7 @@ function wp_write_post() { else $ptype = get_post_type_object('post'); - if ( !current_user_can( $ptype->edit_type_cap ) ) { + if ( !current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' == $ptype->name ) return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) ); else diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 8a9190b722..065518734f 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -876,7 +876,7 @@ function inline_edit_row( $screen ) { $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) ); $col_count = count($columns) - count($hidden); $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list'; - $can_publish = current_user_can($post_type_object->publish_cap); + $can_publish = current_user_can($post_type_object->cap->publish_posts); $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true ); ?> @@ -1111,7 +1111,7 @@ endif; // post_type_supports comments or pings ?> -post_type && $can_publish && current_user_can( $post_type_object->edit_others_cap ) ) : ?> +post_type && $can_publish && current_user_can( $post_type_object->cap->edit_other_posts ) ) : ?> @@ -1181,7 +1181,7 @@ endif; // post_type_supports comments or pings ?> */ function get_inline_data($post) { $post_type_object = get_post_type_object($post->post_type); - if ( ! current_user_can($post_type_object->edit_cap, $post->ID) ) + if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) ) return; $title = esc_attr( get_the_title( $post->ID ) ); @@ -1298,7 +1298,7 @@ function _post_row($a_post, $pending_comments, $mode) { case 'cb': ?> - edit_cap, $post->ID ) ) { ?> + cap->edit_post, $post->ID ) ) { ?> - >edit_cap, $post->ID) && $post->post_status != 'trash' ) { ?> + >cap->edit_post, $post->ID) && $post->post_status != 'trash' ) { ?> edit_cap, $post->ID) && 'trash' != $post->post_status ) { + if ( current_user_can($post_type_object->cap->edit_post, $post->ID) && 'trash' != $post->post_status ) { $actions['edit'] = '' . __('Edit') . ''; $actions['inline hide-if-no-js'] = '' . __('Quick Edit') . ''; } - if ( current_user_can($post_type_object->delete_cap, $post->ID) ) { + if ( current_user_can($post_type_object->cap->delete_post, $post->ID) ) { if ( 'trash' == $post->post_status ) $actions['untrash'] = "ID) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __('Restore') . ""; elseif ( EMPTY_TRASH_DAYS ) @@ -1360,7 +1360,7 @@ function _post_row($a_post, $pending_comments, $mode) { $actions['delete'] = "" . __('Delete Permanently') . ""; } if ( in_array($post->post_status, array('pending', 'draft')) ) { - if ( current_user_can($post_type_object->edit_cap, $post->ID) ) + if ( current_user_can($post_type_object->cap->edit_post, $post->ID) ) $actions['view'] = '' . __('Preview') . ''; } elseif ( 'trash' != $post->post_status ) { $actions['view'] = '' . __('View') . ''; @@ -1443,13 +1443,13 @@ function _post_row($a_post, $pending_comments, $mode) { case 'control_edit': ?> - edit_cap, $post->ID) ) { echo "" . __('Edit') . ""; } ?> + cap->edit_post, $post->ID) ) { echo "" . __('Edit') . ""; } ?> - delete_cap, $post->ID) ) { echo "ID) . "' class='delete'>" . __('Delete') . ""; } ?> + cap->delete_post, $post->ID) ) { echo "ID) . "' class='delete'>" . __('Delete') . ""; } ?> $column_display_name ) { $attributes = 'class="post-title page-title column-title"' . $style; $edit_link = get_edit_post_link( $page->ID ); ?> - >edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?>labels->parent . ' ' . esc_html($parent_name) : ''; ?> + >cap->edit_post, $page->ID) && $post->post_status != 'trash' ) { ?>labels->parent . ' ' . esc_html($parent_name) : ''; ?> edit_cap, $page->ID) && $post->post_status != 'trash' ) { + if ( current_user_can($post_type_object->cap->edit_post, $page->ID) && $post->post_status != 'trash' ) { $actions['edit'] = '' . __('Edit') . ''; $actions['inline'] = '' . __('Quick Edit') . ''; } - if ( current_user_can($post_type_object->delete_cap, $page->ID) ) { + if ( current_user_can($post_type_object->cap->delete_post, $page->ID) ) { if ( $post->post_status == 'trash' ) $actions['untrash'] = "post_type . '_' . $page->ID) . "'>" . __('Restore') . ""; elseif ( EMPTY_TRASH_DAYS ) @@ -1582,7 +1582,7 @@ foreach ( $posts_columns as $column_name => $column_display_name ) { $actions['delete'] = "post_type . '_' . $page->ID) . "'>" . __('Delete Permanently') . ""; } if ( in_array($post->post_status, array('pending', 'draft')) ) { - if ( current_user_can($post_type_object->edit_cap, $page->ID) ) + if ( current_user_can($post_type_object->cap->edit_post, $page->ID) ) $actions['view'] = '' . __('Preview') . ''; } elseif ( $post->post_status != 'trash' ) { $actions['view'] = '' . __('View') . ''; @@ -2010,7 +2010,7 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, $post = get_post($comment->comment_post_ID); $the_comment_status = wp_get_comment_status($comment->comment_ID); $post_type_object = get_post_type_object($post->post_type); - $user_can = current_user_can($post_type_object->edit_cap, $post->ID); + $user_can = current_user_can($post_type_object->cap->edit_post, $post->ID); $comment_url = esc_url(get_comment_link($comment->comment_ID)); $author_url = get_comment_author_url(); @@ -3328,10 +3328,10 @@ function favorite_actions( $screen = null ) { if ( isset($post_type_object) ) { switch ( $screen->id ) { case $post_type_object->name: - $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->edit_type_cap)); + $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->cap->edit_posts)); break; case "edit-{$post_type_object->name}": - $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->edit_type_cap)); + $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts)); break; } } diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 5b1a689dea..6e0c0ff926 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -249,8 +249,8 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'p $user = new WP_User( $user_id ); $post_type_obj = get_post_type_object($post_type); - if ( ! $user->has_cap($post_type_obj->edit_others_cap) ) { - if ( $user->has_cap($post_type_obj->edit_type_cap) || ! $exclude_zeros ) + if ( ! $user->has_cap($post_type_obj->cap->edit_other_posts) ) { + if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros ) return array($user->id); else return array(); diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 19f7f88cd3..8d03e777cf 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -129,9 +129,9 @@ foreach ( (array) get_post_types( array('show_ui' => true) ) as $ptype ) { while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) ) $ptype_menu_position++; - $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->name ), $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-' . $ptype_class, $menu_icon ); - $submenu["edit.php?post_type=$ptype"][5] = array( $ptype_obj->labels->edit, $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype"); - $submenu["edit.php?post_type=$ptype"][10] = array( $ptype_obj->labels->add_new, $ptype_obj->edit_type_cap, "post-new.php?post_type=$ptype" ); + $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->name ), $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-' . $ptype_class, $menu_icon ); + $submenu["edit.php?post_type=$ptype"][5] = array( $ptype_obj->labels->edit, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype"); + $submenu["edit.php?post_type=$ptype"][10] = array( $ptype_obj->labels->add_new, $ptype_obj->cap->edit_posts, "post-new.php?post_type=$ptype" ); $i = 15; foreach ( $wp_taxonomies as $tax ) { diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 91619ccdfd..ec85d55183 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -46,7 +46,7 @@ When you’re promoted, just reload this page and you’ll be able to bl wp_enqueue_script('autosave'); // Show post form. -if ( current_user_can($post_type_object->edit_type_cap) ) { +if ( current_user_can($post_type_object->cap->edit_posts) ) { $post = get_default_post_to_edit( $post_type, true ); $post_ID = $post->ID; include('edit-form-advanced.php'); diff --git a/wp-admin/post.php b/wp-admin/post.php index a8da2b26bd..a8c006c4c4 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -152,7 +152,7 @@ case 'edit': if ( empty($post->ID) ) wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') ); - if ( !current_user_can($post_type_object->edit_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->edit_post, $post_id) ) wp_die( __('You are not allowed to edit this item.') ); if ( 'trash' == $post->post_status ) @@ -217,7 +217,7 @@ case 'trash': $post = & get_post($post_id); - if ( !current_user_can($post_type_object->delete_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to move this item to the Trash.') ); if ( ! wp_trash_post($post_id) ) @@ -230,7 +230,7 @@ case 'trash': case 'untrash': check_admin_referer('untrash-' . $post_type . '_' . $post_id); - if ( !current_user_can($post_type_object->delete_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to move this item out of the Trash.') ); if ( ! wp_untrash_post($post_id) ) @@ -243,7 +243,7 @@ case 'untrash': case 'delete': check_admin_referer('delete-' . $post_type . '_' . $post_id); - if ( !current_user_can($post_type_object->delete_cap, $post_id) ) + if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to delete this item.') ); $force = !EMPTY_TRASH_DAYS; diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index a19139ef32..db7b545ffc 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -823,7 +823,7 @@ function map_meta_cap( $cap, $user_id ) { $post = get_post( $args[0] ); $post_type = get_post_type_object( $post->post_type ); if ( $post_type && 'post' != $post_type->capability_type ) { - $args = array_merge( array( $post_type->delete_cap, $user_id ), $args ); + $args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args ); return call_user_func_array( 'map_meta_cap', $args ); } @@ -900,7 +900,7 @@ function map_meta_cap( $cap, $user_id ) { $post = get_post( $args[0] ); $post_type = get_post_type_object( $post->post_type ); if ( $post_type && 'post' != $post_type->capability_type ) { - $args = array_merge( array( $post_type->edit_cap, $user_id ), $args ); + $args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args ); return call_user_func_array( 'map_meta_cap', $args ); } $post_author_data = get_userdata( $post->post_author ); @@ -959,7 +959,7 @@ function map_meta_cap( $cap, $user_id ) { $post = get_post( $args[0] ); $post_type = get_post_type_object( $post->post_type ); if ( $post_type && 'post' != $post_type->capability_type ) { - $args = array_merge( array( $post_type->read_cap, $user_id ), $args ); + $args = array_merge( array( $post_type->cap->read_post, $user_id ), $args ); return call_user_func_array( 'map_meta_cap', $args ); } diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index d76e34c1c9..cdb6b40648 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -793,7 +793,7 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { if ( !$post_type_object ) return; - if ( !current_user_can( $post_type_object->edit_cap, $post->ID ) ) + if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) return; return apply_filters( 'get_edit_post_link', admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ), $post->ID, $context ); @@ -846,7 +846,7 @@ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false if ( !$post_type_object ) return; - if ( !current_user_can( $post_type_object->delete_cap, $post->ID ) ) + if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) return; $action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; diff --git a/wp-includes/post.php b/wp-includes/post.php index 9d657e01be..4b48bc4f66 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -774,12 +774,7 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon. * - inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none. * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". - * - edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post). - * - edit_type_cap - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts). - * - edit_others_cap - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s" (edit_others_posts). - * - publish_others_cap - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts). - * - read_cap - The capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post). - * - delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post). + * - capabilities - Array of capabilities for this post type. You can see accepted values in {@link get_post_type_capabilities()}. By default the capability_type is used to construct capabilities. * - hierarchical - Whether the post type is hierarchical. Defaults to false. * - supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none. * - register_meta_box_cb - Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback. @@ -802,7 +797,7 @@ function register_post_type($post_type, $args = array()) { // Args prefixed with an underscore are reserved for internal use. $defaults = array( 'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, - '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, + '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'capabilities' => array(), 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'permalink_epmask' => EP_PERMALINK, 'can_export' => true, @@ -827,20 +822,8 @@ function register_post_type($post_type, $args = array()) { if ( empty($args->capability_type) ) $args->capability_type = 'post'; - if ( empty($args->edit_cap) ) - $args->edit_cap = 'edit_' . $args->capability_type; - if ( empty($args->edit_type_cap) ) - $args->edit_type_cap = 'edit_' . $args->capability_type . 's'; - if ( empty($args->edit_others_cap) ) - $args->edit_others_cap = 'edit_others_' . $args->capability_type . 's'; - if ( empty($args->publish_cap) ) - $args->publish_cap = 'publish_' . $args->capability_type . 's'; - if ( empty($args->read_cap) ) - $args->read_cap = 'read_' . $args->capability_type; - if ( empty($args->read_private_cap) ) - $args->read_private_cap = 'read_private_' . $args->capability_type . 's'; - if ( empty($args->delete_cap) ) - $args->delete_cap = 'delete_' . $args->capability_type; + + $args->cap = get_post_type_capabilities( $args ); if ( ! empty($args->supports) ) { add_post_type_support($post_type, $args->supports); @@ -892,6 +875,36 @@ function register_post_type($post_type, $args = array()) { return $args; } +/** + * Builds an object with all post type capabilities out of a post type object + * + * Accepted keys of the capabilities array in the post type object: + * - edit_post - The meta capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post). + * - edit_posts - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts). + * - edit_others_posts - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s" (edit_others_posts). + * - publish_posts - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts). + * - read_post - The meta capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post). + * - read_private_posts - The capability that controls reading private posts. Defaults to "read_ . $capability_type . s" (read_private_posts). + * - delete_post - The meta capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post). + * + * @since 3.0.0 + * @param object $args + * @return object object with all the capabilities as member variables + */ +function get_post_type_capabilities( $args ) { + $defaults = array( + 'edit_post' => 'edit_' . $args->capabilities['capability_type'], + 'edit_posts' => 'edit_' . $args->capabilities['capability_type'] . 's', + 'edit_others_posts' => 'edit_others_' . $args->capabilities['capability_type'] . 's', + 'publish_posts' => 'publish_' . $args->capabilities['capability_type'] . 's', + 'read_post' => 'edit_' . $args->capabilities['capability_type'], + 'read_private_posts' => 'read_private_' . $args->capabilities['capability_type'] . 's', + 'delete_post' => 'delete_' . $args->capabilities['capability_type'], + ); + $labels = array_merge( $defaults, $args->capabilities ); + return (object) $labels; +} + /** * Builds an object with all post type labels out of a post type object * @@ -1525,7 +1538,7 @@ function wp_count_posts( $type = 'post', $perm = '' ) { $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; if ( 'readable' == $perm && is_user_logged_in() ) { $post_type_object = get_post_type_object($type); - if ( !current_user_can( $post_type_object->read_private_cap ) ) { + if ( !current_user_can( $post_type_object->cap->read_private_posts ) ) { $cache_key .= '_' . $perm . '_' . $user->ID; $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; } diff --git a/wp-includes/query.php b/wp-includes/query.php index 8d5422bebe..ce275f1b25 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2192,10 +2192,10 @@ class WP_Query { if ( !empty($post_type_object) ) { $post_type_cap = $post_type_object->capability_type; - $edit_cap = $post_type_object->edit_cap; - $read_cap = $post_type_object->read_cap; - $edit_others_cap = $post_type_object->edit_others_cap; - $read_private_cap = $post_type_object->read_private_cap; + $edit_cap = $post_type_object->cap->edit_post; + $read_cap = $post_type_object->cap->read_post; + $edit_others_cap = $post_type_object->cap->edit_other_posts; + $read_private_cap = $post_type_object->cap->read_private_posts; } else { $edit_cap = 'edit_' . $post_type_cap; $read_cap = 'read_' . $post_type_cap;