Make WordPress Core


Ignore:
Timestamp:
05/12/2010 08:45:18 PM (15 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.