Make WordPress Core


Ignore:
Timestamp:
02/02/2010 05:37:03 PM (17 years ago)
Author:
ryan
Message:

Allow customizing capabilities for custom post types. Always check caps against those in the post type object instead of contructing them manually. see #9674

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r12859 r12927  
    11291129        $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
    11301130        // @todo use capability_type
    1131         $can_publish = current_user_can("publish_{$screen->post_type}s");
     1131        $can_publish = current_user_can($post_type_object->publish_cap);
    11321132        $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
    11331133
     
    13361336                        </label>
    13371337
    1338 <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( 'edit_others_posts' ) ) : ?>
     1338<?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->edit_others_cap ) ) : ?>
    13391339
    13401340<?php   if ( $bulk ) : ?>
     
    13581358<?php   endif; // $bulk ?>
    13591359
    1360 <?php endif; // !$is_page && $can_publish && current_user_can( 'edit_others_posts' ) ?>
     1360<?php endif; // !$is_page && $can_publish && current_user_can( 'edit_others_cap' ) ?>
    13611361
    13621362                </div>
     
    14051405 */
    14061406function get_inline_data($post) {
    1407 
    1408         if ( ! current_user_can('edit_' . $post->post_type, $post->ID) )
     1407        $post_type_object = get_post_type_object($post->post_type);
     1408        if ( ! current_user_can($post_type_object->edit_cap, $post->ID) )
    14091409                return;
    14101410
     
    14271427        <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
    14281428
     1429        if ( $post_type_object->hierarchical )
     1430                echo '<div class="post_parent">' . $post->post_parent . '</div>';
     1431
    14291432        if ( $post->post_type == 'page' )
    1430                 echo '
    1431         <div class="post_parent">' . $post->post_parent . '</div>
    1432         <div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>
    1433         <div class="menu_order">' . $post->menu_order . '</div>';
     1433                echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
     1434
     1435        if ( $post_type_object->hierarchical )
     1436                echo '<div class="menu_order">' . $post->menu_order . '</div>';
     1437
     1438        if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
     1439                echo '<div class="tags_input">' . esc_html( str_replace( ',', ', ', get_tags_to_edit($post->ID) ) ) . '</div>';
     1440
     1441        if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
     1442                echo '<div class="post_category">' . implode( ',', wp_get_post_categories( $post->ID ) ) . '</div>';
    14341443
    14351444        if ( $post->post_type == 'post' )
    1436                 echo '
    1437         <div class="tags_input">' . esc_html( str_replace( ',', ', ', get_tags_to_edit($post->ID) ) ) . '</div>
    1438         <div class="post_category">' . implode( ',', wp_get_post_categories( $post->ID ) ) . '</div>
    1439         <div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
     1445                echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
    14401446
    14411447        echo '</div>';
     
    14961502        $edit_link = get_edit_post_link( $post->ID );
    14971503        $title = _draft_or_post_title();
     1504        $post_type_object = get_post_type_object($post->post_type);
    14981505?>
    14991506        <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $rowclass . ' author-' . $post_owner . ' status-' . $post->post_status ); ?> iedit' valign="top">
     
    15141521                case 'cb':
    15151522                ?>
    1516                 <th scope="row" class="check-column"><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
     1523                <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>
    15171524                <?php
    15181525                break;
     
    15571564                        $attributes = 'class="post-title column-title"' . $style;
    15581565                ?>
    1559                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can('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>
     1566                <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>
    15601567                <?php
    15611568                        if ( 'excerpt' == $mode )
     
    15631570
    15641571                        $actions = array();
    1565                         if ( current_user_can('edit_post', $post->ID) && 'trash' != $post->post_status ) {
     1572                        if ( current_user_can($post_type_object->edit_cap, $post->ID) && 'trash' != $post->post_status ) {
    15661573                                $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
    15671574                                $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
    15681575                        }
    1569                         if ( current_user_can('delete_post', $post->ID) ) {
     1576                        if ( current_user_can($post_type_object->delete_cap, $post->ID) ) {
    15701577                                if ( 'trash' == $post->post_status )
    15711578                                        $actions['untrash'] = "<a title='" . esc_attr(__('Restore this post from the Trash')) . "' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
     
    15761583                        }
    15771584                        if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1578                                 if ( current_user_can('edit_post', $post->ID) )
     1585                                if ( current_user_can($post_type_object->edit_cap, $post->ID) )
    15791586                                        $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
    15801587                        } elseif ( 'trash' != $post->post_status ) {
     
    16591666                case 'control_edit':
    16601667                ?>
    1661                 <td><?php if ( current_user_can('edit_post', $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
     1668                <td><?php if ( current_user_can($post_type_object->edit_cap, $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
    16621669                <?php
    16631670                break;
     
    16651672                case 'control_delete':
    16661673                ?>
    1667                 <td><?php if ( current_user_can('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>
     1674                <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>
    16681675                <?php
    16691676                break;
     
    17261733        $title = _draft_or_post_title();
    17271734        $post_type = $page->post_type;
     1735        $post_type_object = get_post_type_object($post_type);
    17281736?>
    17291737<tr id="page-<?php echo $id; ?>" class="<?php echo $rowclass; ?> iedit">
    17301738<?php
    17311739
    1732 foreach ($posts_columns as $column_name=>$column_display_name) {
     1740foreach ( $posts_columns as $column_name => $column_display_name ) {
    17331741        $class = "class=\"$column_name column-$column_name\"";
    17341742
     
    17811789                $edit_link = get_edit_post_link( $page->ID );
    17821790                ?>
    1783                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can('edit_page', $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) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
     1791                <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) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
    17841792                <?php
    17851793                $actions = array();
    1786                 if ( current_user_can('edit_page', $page->ID) && $post->post_status != 'trash' ) {
     1794                if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) {
    17871795                        $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
    17881796                        $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
    17891797                }
    1790                 if ( current_user_can('delete_page', $page->ID) ) {
     1798                if ( current_user_can($post_type_object->delete_cap, $page->ID) ) {
    17911799                        if ( $post->post_status == 'trash' )
    17921800                                $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-page_' . $page->ID) . "'>" . __('Restore') . "</a>";
     
    17971805                }
    17981806                if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1799                         if ( current_user_can('edit_page', $page->ID) )
     1807                        if ( current_user_can($post_type_object->edit_cap, $page->ID) )
    18001808                                $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
    18011809                } elseif ( $post->post_status != 'trash' ) {
     
    22152223        $post = get_post($comment->comment_post_ID);
    22162224        $the_comment_status = wp_get_comment_status($comment->comment_ID);
    2217         $user_can = current_user_can('edit_post', $post->ID);
     2225        $post_type_object = get_post_type_object($post->post_type);
     2226        $user_can = current_user_can($post_type_object->edit_cap, $post->ID);
    22182227
    22192228        $author_url = get_comment_author_url();
Note: See TracChangeset for help on using the changeset viewer.