Ticket #16714: 16714.6.diff

File 16714.6.diff, 4.8 KB (added by ryan, 7 months ago)

Custom edit_posts should be used for create_posts if create_posts not specified

Line 
1Index: wp-includes/post.php
2===================================================================
3--- wp-includes/post.php        (revision 22290)
4+++ wp-includes/post.php        (working copy)
5@@ -1411,8 +1411,6 @@
6                'edit_others_posts'  => 'edit_others_'  . $plural_base,
7                'publish_posts'      => 'publish_'      . $plural_base,
8                'read_private_posts' => 'read_private_' . $plural_base,
9-               // Post creation capability simply maps to edit_posts by default:
10-               'create_posts'       => 'edit_'         . $plural_base,
11        );
12 
13        // Primitive capabilities used within map_meta_cap():
14@@ -1431,6 +1429,10 @@
15 
16        $capabilities = array_merge( $default_capabilities, $args->capabilities );
17 
18+       // Post creation capability simply maps to edit_posts by default:
19+       if ( ! isset( $capabilities['create_posts'] ) )
20+               $capabilities['create_posts'] = $capabilities['edit_posts'];
21+
22        // Remember meta capabilities for future reference.
23        if ( $args->map_meta_cap )
24                _post_type_meta_capabilities( $capabilities );
25Index: wp-admin/post-new.php
26===================================================================
27--- wp-admin/post-new.php       (revision 22290)
28+++ wp-admin/post-new.php       (working copy)
29@@ -36,7 +36,7 @@
30 
31 $editing = true;
32 
33-if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
34+if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $post_type_object->cap->create_posts ) )
35        wp_die( __( 'Cheatin’ uh?' ) );
36 
37 // Schedule auto-draft cleanup
38Index: wp-admin/index.php
39===================================================================
40--- wp-admin/index.php  (revision 22290)
41+++ wp-admin/index.php  (working copy)
42@@ -76,7 +76,7 @@
43        $help .= '<p>' . __('<strong>Recent Comments</strong> - Shows the most recent comments on your posts (configurable, up to 30) and allows you to moderate them.') . '</p>';
44 if ( current_user_can( 'publish_posts' ) )
45        $help .= '<p>' . __('<strong>Incoming Links</strong> - Shows links to your site found by Google Blog Search.') . '</p>';
46-if ( current_user_can( 'edit_posts' ) ) {
47+if ( current_user_can( 'create_posts' ) ) {
48        $help .= '<p>' . __('<strong>QuickPress</strong> - Allows you to create a new post and either publish it or save it as a draft.') . '</p>';
49        $help .= '<p>' . __('<strong>Recent Drafts</strong> - Displays links to the 5 most recent draft posts you&#8217;ve started.') . '</p>';
50 }
51Index: wp-admin/edit-form-advanced.php
52===================================================================
53--- wp-admin/edit-form-advanced.php     (revision 22290)
54+++ wp-admin/edit-form-advanced.php     (working copy)
55@@ -274,7 +274,11 @@
56 
57 <div class="wrap">
58 <?php screen_icon(); ?>
59-<h2><?php echo esc_html( $title ); ?><?php if ( isset( $post_new_file ) ) : ?> <a href="<?php echo esc_url( $post_new_file ) ?>" class="add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a><?php endif; ?></h2>
60+<h2><?php
61+echo esc_html( $title );
62+if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create_posts ) )
63+       echo ' <a href="' . esc_url( $post_new_file ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
64+?></h2>
65 <?php if ( $notice ) : ?>
66 <div id="notice" class="error"><p><?php echo $notice ?></p></div>
67 <?php endif; ?>
68Index: wp-admin/edit.php
69===================================================================
70--- wp-admin/edit.php   (revision 22290)
71+++ wp-admin/edit.php   (working copy)
72@@ -221,10 +221,13 @@
73 ?>
74 <div class="wrap">
75 <?php screen_icon(); ?>
76-<h2><?php echo esc_html( $post_type_object->labels->name ); ?> <a href="<?php echo $post_new_file ?>" class="add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a> <?php
77+<h2><?php
78+echo esc_html( $post_type_object->labels->name );
79+if ( current_user_can( $post_type_object->cap->create_posts ) )
80+       echo ' <a href="' . esc_url( $post_new_file ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
81 if ( ! empty( $_REQUEST['s'] ) )
82-       printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
83-</h2>
84+       printf( ' <span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() );
85+?></h2>
86 
87 <?php if ( isset( $_REQUEST['locked'] ) || isset( $_REQUEST['updated'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) ) {
88        $messages = array();
89Index: wp-admin/press-this.php
90===================================================================
91--- wp-admin/press-this.php     (revision 22290)
92+++ wp-admin/press-this.php     (working copy)
93@@ -13,7 +13,7 @@
94 
95 header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
96 
97-if ( ! current_user_can('edit_posts') )
98+if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( 'create_posts' ) )
99        wp_die( __( 'Cheatin&#8217; uh?' ) );
100 
101 /**