Make WordPress Core

Changeset 14585


Ignore:
Timestamp:
05/12/2010 08:45:18 PM (16 years ago)
Author:
nacin
Message:

Move post type object capabilities to a 'cap' object. Allow them to be initialized via the 'capabilities' key (an array) when registering support for the post type. Caps are now referred to by the name of the cap as if it was a post, i.e. ->cap->edit_post. see #13358.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r14554 r14585  
    143143        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
    144144
    145 if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) )
     145if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
    146146        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
    147147
    … …  
    222222    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
    223223
    224 if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) ) { ?>
     224if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
    225225        <div id="edit-slug-box">
    226226        <?php
  • trunk/wp-admin/edit.php

    r14571 r14585  
    2020$post_type_object = get_post_type_object($post_type);
    2121
    22 if ( !current_user_can($post_type_object->edit_type_cap) )
     22if ( !current_user_can($post_type_object->cap->edit_posts) )
    2323        wp_die(__('Cheatin&#8217; uh?'));
    2424
    … …  
    7474                        $trashed = 0;
    7575                        foreach( (array) $post_ids as $post_id ) {
    76                                 if ( !current_user_can($post_type_object->delete_cap, $post_id) )
     76                                if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    7777                                        wp_die( __('You are not allowed to move this item to the Trash.') );
    7878
    … …  
    8787                        $untrashed = 0;
    8888                        foreach( (array) $post_ids as $post_id ) {
    89                                 if ( !current_user_can($post_type_object->delete_cap, $post_id) )
     89                                if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    9090                                        wp_die( __('You are not allowed to restore this item from the Trash.') );
    9191
    … …  
    102102                                $post_del = & get_post($post_id);
    103103
    104                                 if ( !current_user_can($post_type_object->delete_cap, $post_id) )
     104                                if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    105105                                        wp_die( __('You are not allowed to delete this item.') );
    106106
    … …  
    141141
    142142$user_posts = false;
    143 if ( !current_user_can($post_type_object->edit_others_cap) ) {
     143if ( !current_user_can($post_type_object->cap->edit_other_posts) ) {
    144144        $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) );
    145145        $user_posts = true;
    … …  
    346346<?php }
    347347
    348 if ( $is_trash && current_user_can($post_type_object->edit_others_cap) ) { ?>
     348if ( $is_trash && current_user_can($post_type_object->cap->edit_other_posts) ) { ?>
    349349<input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    350350<?php } ?>
    … …  
    397397</select>
    398398<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
    399 <?php if ( $is_trash && current_user_can($post_type_object->edit_others_cap) ) { ?>
     399<?php if ( $is_trash && current_user_can($post_type_object->cap->edit_other_posts) ) { ?>
    400400<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    401401<?php } ?>
  • trunk/wp-admin/includes/meta-boxes.php

    r14426 r14585  
    1515        $post_type = $post->post_type;
    1616        $post_type_object = get_post_type_object($post_type);
    17         $can_publish = current_user_can($post_type_object->publish_cap);
     17        $can_publish = current_user_can($post_type_object->cap->publish_posts);
    1818?>
    1919<div class="submitbox" id="submitpost">
  • trunk/wp-admin/includes/post.php

    r14580 r14585  
    4747        $ptype = get_post_type_object( $post_data['post_type'] );
    4848        if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {
    49                 if ( !current_user_can( $ptype->edit_others_cap ) ) {
     49                if ( !current_user_can( $ptype->cap->edit_other_posts ) ) {
    5050                        if ( 'page' == $post_data['post_type'] ) {
    5151                                return new WP_Error( 'edit_others_pages', $update ?
    … …  
    8282        // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
    8383        // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
    84         if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->publish_cap )) )
     84        if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) )
    8585                if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) )
    8686                        $post_data['post_status'] = 'pending';
    … …  
    139139
    140140        $ptype = get_post_type_object($post_data['post_type']);
    141         if ( !current_user_can( $ptype->edit_cap, $post_ID ) ) {
     141        if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) {
    142142                if ( 'page' == $post_data['post_type'] )
    143143                        wp_die( __('You are not allowed to edit this page.' ));
    … …  
    238238                $ptype = get_post_type_object('post');
    239239
    240         if ( !current_user_can( $ptype->edit_type_cap ) ) {
     240        if ( !current_user_can( $ptype->cap->edit_posts ) ) {
    241241                if ( 'page' == $ptype->name )
    242242                        wp_die( __('You are not allowed to edit pages.'));
    … …  
    495495                $ptype = get_post_type_object('post');
    496496
    497         if ( !current_user_can( $ptype->edit_type_cap ) ) {
     497        if ( !current_user_can( $ptype->cap->edit_posts ) ) {
    498498                if ( 'page' == $ptype->name )
    499499                        return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) );
  • trunk/wp-admin/includes/template.php

    r14571 r14585  
    877877        $col_count = count($columns) - count($hidden);
    878878        $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
    879         $can_publish = current_user_can($post_type_object->publish_cap);
     879        $can_publish = current_user_can($post_type_object->cap->publish_posts);
    880880        $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
    881881
    … …  
    11121112                        </label>
    11131113
    1114 <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->edit_others_cap ) ) : ?>
     1114<?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_other_posts ) ) : ?>
    11151115
    11161116<?php   if ( $bulk ) : ?>
    … …  
    11821182function get_inline_data($post) {
    11831183        $post_type_object = get_post_type_object($post->post_type);
    1184         if ( ! current_user_can($post_type_object->edit_cap, $post->ID) )
     1184        if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) )
    11851185                return;
    11861186
    … …  
    12991299                case 'cb':
    13001300                ?>
    1301                 <th scope="row" class="check-column"><?php if ( current_user_can( $post_type_object->edit_cap, $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
     1301                <th scope="row" class="check-column"><?php if ( current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
    13021302                <?php
    13031303                break;
    … …  
    13421342                        $attributes = 'class="post-title column-title"' . $style;
    13431343                ?>
    1344                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->edit_cap, $post->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
     1344                <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->cap->edit_post, $post->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
    13451345                <?php
    13461346                        if ( 'excerpt' == $mode )
    … …  
    13481348
    13491349                        $actions = array();
    1350                         if ( current_user_can($post_type_object->edit_cap, $post->ID) && 'trash' != $post->post_status ) {
     1350                        if ( current_user_can($post_type_object->cap->edit_post, $post->ID) && 'trash' != $post->post_status ) {
    13511351                                $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
    13521352                                $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
    13531353                        }
    1354                         if ( current_user_can($post_type_object->delete_cap, $post->ID) ) {
     1354                        if ( current_user_can($post_type_object->cap->delete_post, $post->ID) ) {
    13551355                                if ( 'trash' == $post->post_status )
    13561356                                        $actions['untrash'] = "<a title='" . esc_attr(__('Restore this post from the Trash')) . "' href='" . wp_nonce_url( admin_url( sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __('Restore') . "</a>";
    … …  
    13611361                        }
    13621362                        if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1363                                 if ( current_user_can($post_type_object->edit_cap, $post->ID) )
     1363                                if ( current_user_can($post_type_object->cap->edit_post, $post->ID) )
    13641364                                        $actions['view'] = '<a href="' . add_query_arg( 'preview', 'true', get_permalink($post->ID) ) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
    13651365                        } elseif ( 'trash' != $post->post_status ) {
    … …  
    14441444                case 'control_edit':
    14451445                ?>
    1446                 <td><?php if ( current_user_can($post_type_object->edit_cap, $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
     1446                <td><?php if ( current_user_can($post_type_object->cap->edit_post, $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
    14471447                <?php
    14481448                break;
    … …  
    14501450                case 'control_delete':
    14511451                ?>
    1452                 <td><?php if ( current_user_can($post_type_object->delete_cap, $post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
     1452                <td><?php if ( current_user_can($post_type_object->cap->delete_post, $post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
    14531453                <?php
    14541454                break;
    … …  
    15671567                $edit_link = get_edit_post_link( $page->ID );
    15681568                ?>
    1569                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . $post_type_object->labels->parent . ' ' . esc_html($parent_name) : ''; ?></strong>
     1569                <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->cap->edit_post, $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . $post_type_object->labels->parent . ' ' . esc_html($parent_name) : ''; ?></strong>
    15701570                <?php
    15711571                $actions = array();
    1572                 if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) {
     1572                if ( current_user_can($post_type_object->cap->edit_post, $page->ID) && $post->post_status != 'trash' ) {
    15731573                        $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
    15741574                        $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
    15751575                }
    1576                 if ( current_user_can($post_type_object->delete_cap, $page->ID) ) {
     1576                if ( current_user_can($post_type_object->cap->delete_post, $page->ID) ) {
    15771577                        if ( $post->post_status == 'trash' )
    15781578                                $actions['untrash'] = "<a title='" . esc_attr(__('Remove this page from the Trash')) . "' href='" . wp_nonce_url("post.php?post_type=$post_type&amp;action=untrash&amp;post=$page->ID", 'untrash-' . $post->post_type . '_' . $page->ID) . "'>" . __('Restore') . "</a>";
    … …  
    15831583                }
    15841584                if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1585                         if ( current_user_can($post_type_object->edit_cap, $page->ID) )
     1585                        if ( current_user_can($post_type_object->cap->edit_post, $page->ID) )
    15861586                                $actions['view'] = '<a href="' . add_query_arg( 'preview', 'true', get_permalink($page->ID) ) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
    15871587                } elseif ( $post->post_status != 'trash' ) {
    … …  
    20112011        $the_comment_status = wp_get_comment_status($comment->comment_ID);
    20122012        $post_type_object = get_post_type_object($post->post_type);
    2013         $user_can = current_user_can($post_type_object->edit_cap, $post->ID);
     2013        $user_can = current_user_can($post_type_object->cap->edit_post, $post->ID);
    20142014
    20152015        $comment_url = esc_url(get_comment_link($comment->comment_ID));
    … …  
    33293329                switch ( $screen->id ) {
    33303330                        case $post_type_object->name:
    3331                                 $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->edit_type_cap));
     3331                                $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->cap->edit_posts));
    33323332                                break;
    33333333                        case "edit-{$post_type_object->name}":
    3334                                 $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));
     3334                                $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));
    33353335                                break;
    33363336                }
  • trunk/wp-admin/includes/user.php

    r14428 r14585  
    250250        $post_type_obj = get_post_type_object($post_type);
    251251
    252         if ( ! $user->has_cap($post_type_obj->edit_others_cap) ) {
    253                 if ( $user->has_cap($post_type_obj->edit_type_cap) || ! $exclude_zeros )
     252        if ( ! $user->has_cap($post_type_obj->cap->edit_other_posts) ) {
     253                if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros )
    254254                        return array($user->id);
    255255                else
  • trunk/wp-admin/menu.php

    r14581 r14585  
    130130                $ptype_menu_position++;
    131131
    132         $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 );
    133         $submenu["edit.php?post_type=$ptype"][5]  = array( $ptype_obj->labels->edit, $ptype_obj->edit_type_cap,  "edit.php?post_type=$ptype");
    134         $submenu["edit.php?post_type=$ptype"][10]  = array( $ptype_obj->labels->add_new, $ptype_obj->edit_type_cap, "post-new.php?post_type=$ptype" );
     132        $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 );
     133        $submenu["edit.php?post_type=$ptype"][5]  = array( $ptype_obj->labels->edit, $ptype_obj->cap->edit_posts,  "edit.php?post_type=$ptype");
     134        $submenu["edit.php?post_type=$ptype"][10]  = array( $ptype_obj->labels->add_new, $ptype_obj->cap->edit_posts, "post-new.php?post_type=$ptype" );
    135135
    136136        $i = 15;
  • trunk/wp-admin/post-new.php

    r14571 r14585  
    4747
    4848// Show post form.
    49 if ( current_user_can($post_type_object->edit_type_cap) ) {
     49if ( current_user_can($post_type_object->cap->edit_posts) ) {
    5050        $post = get_default_post_to_edit( $post_type, true );
    5151        $post_ID = $post->ID;
  • trunk/wp-admin/post.php

    r14571 r14585  
    153153                wp_die( __('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?') );
    154154
    155         if ( !current_user_can($post_type_object->edit_cap, $post_id) )
     155        if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )
    156156                wp_die( __('You are not allowed to edit this item.') );
    157157
    … …  
    218218        $post = & get_post($post_id);
    219219
    220         if ( !current_user_can($post_type_object->delete_cap, $post_id) )
     220        if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    221221                wp_die( __('You are not allowed to move this item to the Trash.') );
    222222
    … …  
    231231        check_admin_referer('untrash-' . $post_type . '_' . $post_id);
    232232
    233         if ( !current_user_can($post_type_object->delete_cap, $post_id) )
     233        if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    234234                wp_die( __('You are not allowed to move this item out of the Trash.') );
    235235
    … …  
    244244        check_admin_referer('delete-' . $post_type . '_' . $post_id);
    245245
    246         if ( !current_user_can($post_type_object->delete_cap, $post_id) )
     246        if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    247247                wp_die( __('You are not allowed to delete this item.') );
    248248
  • trunk/wp-includes/capabilities.php

    r14404 r14585  
    824824                $post_type = get_post_type_object( $post->post_type );
    825825                if ( $post_type && 'post' != $post_type->capability_type ) {
    826                         $args = array_merge( array( $post_type->delete_cap, $user_id ), $args );
     826                        $args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args );
    827827                        return call_user_func_array( 'map_meta_cap', $args );
    828828                }
    … …  
    901901                $post_type = get_post_type_object( $post->post_type );
    902902                if ( $post_type && 'post' != $post_type->capability_type ) {
    903                         $args = array_merge( array( $post_type->edit_cap, $user_id ), $args );
     903                        $args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
    904904                        return call_user_func_array( 'map_meta_cap', $args );
    905905                }
    … …  
    960960                $post_type = get_post_type_object( $post->post_type );
    961961                if ( $post_type && 'post' != $post_type->capability_type ) {
    962                         $args = array_merge( array( $post_type->read_cap, $user_id ), $args );
     962                        $args = array_merge( array( $post_type->cap->read_post, $user_id ), $args );
    963963                        return call_user_func_array( 'map_meta_cap', $args );
    964964                }
  • trunk/wp-includes/link-template.php

    r14490 r14585  
    794794                return;
    795795
    796         if ( !current_user_can( $post_type_object->edit_cap, $post->ID ) )
     796        if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) )
    797797                return;
    798798
    … …  
    847847                return;
    848848
    849         if ( !current_user_can( $post_type_object->delete_cap, $post->ID ) )
     849        if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
    850850                return;
    851851
  • trunk/wp-includes/post.php

    r14584 r14585  
    775775 * - inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none.
    776776 * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post".
    777  * - edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post).
    778  * - edit_type_cap - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts).
    779  * - 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).
    780  * - publish_others_cap - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts).
    781  * - read_cap - The capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post).
    782  * - delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post).
     777 * - 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.
    783778 * - hierarchical - Whether the post type is hierarchical. Defaults to false.
    784779 * - supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
    … …  
    803798        $defaults = array(
    804799                'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
    805                 '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false,
     800                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'capabilities' => array(), 'hierarchical' => false,
    806801                'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null,
    807802                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
    … …  
    828823        if ( empty($args->capability_type) )
    829824                $args->capability_type = 'post';
    830         if ( empty($args->edit_cap) )
    831                 $args->edit_cap = 'edit_' . $args->capability_type;
    832         if ( empty($args->edit_type_cap) )
    833                 $args->edit_type_cap = 'edit_' . $args->capability_type . 's';
    834         if ( empty($args->edit_others_cap) )
    835                 $args->edit_others_cap = 'edit_others_' . $args->capability_type . 's';
    836         if ( empty($args->publish_cap) )
    837                 $args->publish_cap = 'publish_' . $args->capability_type . 's';
    838         if ( empty($args->read_cap) )
    839                 $args->read_cap = 'read_' . $args->capability_type;
    840         if ( empty($args->read_private_cap) )
    841                 $args->read_private_cap = 'read_private_' . $args->capability_type . 's';
    842         if ( empty($args->delete_cap) )
    843                 $args->delete_cap = 'delete_' . $args->capability_type;
     825
     826        $args->cap = get_post_type_capabilities( $args );
    844827
    845828        if ( ! empty($args->supports) ) {
    … …  
    891874
    892875        return $args;
     876}
     877
     878/**
     879 * Builds an object with all post type capabilities out of a post type object
     880 *
     881 * Accepted keys of the capabilities array in the post type object:
     882 * - edit_post - The meta capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post).
     883 * - edit_posts - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts).
     884 * - 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).
     885 * - publish_posts - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts).
     886 * - read_post - The meta capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post).
     887 * - read_private_posts - The capability that controls reading private posts. Defaults to "read_ . $capability_type . s" (read_private_posts).
     888 * - delete_post - The meta capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post).
     889 *
     890 * @since 3.0.0
     891 * @param object $args
     892 * @return object object with all the capabilities as member variables
     893 */
     894function get_post_type_capabilities( $args ) {
     895        $defaults = array(
     896                'edit_post'          => 'edit_'         . $args->capabilities['capability_type'],
     897                'edit_posts'         => 'edit_'         . $args->capabilities['capability_type'] . 's',
     898                'edit_others_posts'  => 'edit_others_'  . $args->capabilities['capability_type'] . 's',
     899                'publish_posts'      => 'publish_'      . $args->capabilities['capability_type'] . 's',
     900                'read_post'          => 'edit_'         . $args->capabilities['capability_type'],
     901                'read_private_posts' => 'read_private_' . $args->capabilities['capability_type'] . 's',
     902                'delete_post'        => 'delete_'       . $args->capabilities['capability_type'],
     903        );
     904        $labels = array_merge( $defaults, $args->capabilities );
     905        return (object) $labels;
    893906}
    894907
    … …  
    15261539        if ( 'readable' == $perm && is_user_logged_in() ) {
    15271540                $post_type_object = get_post_type_object($type);
    1528                 if ( !current_user_can( $post_type_object->read_private_cap ) ) {
     1541                if ( !current_user_can( $post_type_object->cap->read_private_posts ) ) {
    15291542                        $cache_key .= '_' . $perm . '_' . $user->ID;
    15301543                        $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))";
  • trunk/wp-includes/query.php

    r14565 r14585  
    21932193                if ( !empty($post_type_object) ) {
    21942194                        $post_type_cap = $post_type_object->capability_type;
    2195                         $edit_cap = $post_type_object->edit_cap;
    2196                         $read_cap = $post_type_object->read_cap;
    2197                         $edit_others_cap = $post_type_object->edit_others_cap;
    2198                         $read_private_cap = $post_type_object->read_private_cap;
     2195                        $edit_cap = $post_type_object->cap->edit_post;
     2196                        $read_cap = $post_type_object->cap->read_post;
     2197                        $edit_others_cap = $post_type_object->cap->edit_other_posts;
     2198                        $read_private_cap = $post_type_object->cap->read_private_posts;
    21992199                } else {
    22002200                        $edit_cap = 'edit_' . $post_type_cap;
Note: See TracChangeset for help on using the changeset viewer.