Ticket #35614: 35614.3.patch
| File 35614.3.patch, 17.5 KB (added by , 10 years ago) |
|---|
-
src/wp-admin/edit-tags.php
diff --git src/wp-admin/edit-tags.php src/wp-admin/edit-tags.php index 76e7204..b048103 100644
108 108 $tag_ID = (int) $_REQUEST['tag_ID']; 109 109 check_admin_referer( 'delete-tag_' . $tag_ID ); 110 110 111 if ( ! current_user_can( $tax->cap->delete_terms) ) {111 if ( ! current_user_can( 'delete_term', $tag_ID ) ) { 112 112 wp_die( 113 113 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 114 114 '<p>' . __( 'Sorry, you are not allowed to delete this item.' ) . '</p>', … … 168 168 $tag_ID = (int) $_POST['tag_ID']; 169 169 check_admin_referer( 'update-tag_' . $tag_ID ); 170 170 171 if ( ! current_user_can( $tax->cap->edit_terms) ) {171 if ( ! current_user_can( 'edit_term', $tag_ID ) ) { 172 172 wp_die( 173 173 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 174 174 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', … … 313 313 } 314 314 315 315 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 316 317 if ( ! current_user_can( $tax->cap->edit_terms ) ) {318 wp_die(319 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .320 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',321 403322 );323 }324 316 325 317 /** Also used by the Edit Tag form */ 326 318 require_once( ABSPATH . 'wp-admin/includes/edit-tag-messages.php' ); -
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index 561c37b..6e43384 100644
594 594 $tag_id = (int) $_POST['tag_ID']; 595 595 check_ajax_referer( "delete-tag_$tag_id" ); 596 596 597 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; 598 $tax = get_taxonomy($taxonomy); 599 600 if ( !current_user_can( $tax->cap->delete_terms ) ) 597 if ( ! current_user_can( 'delete_term', $tag_id ) ) { 601 598 wp_die( -1 ); 599 } 602 600 601 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; 603 602 $tag = get_term( $tag_id, $taxonomy ); 604 603 if ( !$tag || is_wp_error( $tag ) ) 605 604 wp_die( 1 ); … … 796 795 if ( empty( $action ) ) 797 796 $action = 'add-link-category'; 798 797 check_ajax_referer( $action ); 799 if ( !current_user_can( 'manage_categories' ) ) 798 $tax = get_taxonomy( 'link_category' ); 799 if ( ! current_user_can( $tax->cap->manage_terms ) ) { 800 800 wp_die( -1 ); 801 } 801 802 $names = explode(',', wp_unslash( $_POST['newcat'] ) ); 802 803 $x = new WP_Ajax_Response(); 803 804 foreach ( $names as $cat_name ) { … … 1703 1704 if ( ! $tax ) 1704 1705 wp_die( 0 ); 1705 1706 1706 if ( ! current_user_can( $tax->cap->edit_terms ) )1707 if ( ! isset( $_POST['tax_ID'] ) || ! ( $id = (int) $_POST['tax_ID'] ) ) { 1707 1708 wp_die( -1 ); 1709 } 1710 1711 if ( ! current_user_can( 'edit_term', $id ) ) { 1712 wp_die( -1 ); 1713 } 1708 1714 1709 1715 $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) ); 1710 1711 if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )1712 wp_die( -1 );1713 1716 1714 1717 $tag = get_term( $id, $taxonomy ); 1715 1718 $_POST['description'] = $tag->description; -
src/wp-admin/includes/class-wp-terms-list-table.php
diff --git src/wp-admin/includes/class-wp-terms-list-table.php src/wp-admin/includes/class-wp-terms-list-table.php index 6e9f9c6..aa3ac38 100644
151 151 */ 152 152 protected function get_bulk_actions() { 153 153 $actions = array(); 154 $actions['delete'] = __( 'Delete' ); 154 155 if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) ) { 156 $actions['delete'] = __( 'Delete' ); 157 } 155 158 156 159 return $actions; 157 160 } … … 332 335 * @return string 333 336 */ 334 337 public function column_cb( $tag ) { 335 $default_term = get_option( 'default_' . $this->screen->taxonomy ); 336 337 if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term ) 338 if ( current_user_can( 'delete_term', $tag->term_id ) ) { 338 339 return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>' 339 340 . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />'; 341 } 340 342 341 343 return ' '; 342 344 } … … 423 425 424 426 $taxonomy = $this->screen->taxonomy; 425 427 $tax = get_taxonomy( $taxonomy ); 426 $default_term = get_option( 'default_' . $taxonomy );427 428 428 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; 429 429 430 430 $edit_link = add_query_arg( … … 434 434 ); 435 435 436 436 $actions = array(); 437 if ( current_user_can( $tax->cap->edit_terms) ) {437 if ( current_user_can( 'edit_term', $tag->term_id ) ) { 438 438 $actions['edit'] = sprintf( 439 439 '<a href="%s" aria-label="%s">%s</a>', 440 440 esc_url( $edit_link ), … … 449 449 __( 'Quick Edit' ) 450 450 ); 451 451 } 452 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term) {452 if ( current_user_can( 'delete_term', $tag->term_id ) ) { 453 453 $actions['delete'] = sprintf( 454 454 '<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>', 455 455 wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ), -
src/wp-admin/includes/meta-boxes.php
diff --git src/wp-admin/includes/meta-boxes.php src/wp-admin/includes/meta-boxes.php index 2d12faf..8a79c22 100644
434 434 <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" /></p> 435 435 </div> 436 436 <p class="howto" id="new-tag-<?php echo $tax_name; ?>-desc"><?php echo $taxonomy->labels->separate_items_with_commas; ?></p> 437 <?php elseif ( empty( $terms_to_edit ) ): ?> 438 <p><?php echo $taxonomy->labels->no_terms; ?></p> 437 439 <?php endif; ?> 438 440 </div> 439 441 <div class="tagchecklist"></div> -
src/wp-admin/term.php
diff --git src/wp-admin/term.php src/wp-admin/term.php index dc3f1d5..2018ac0 100644
31 31 $title = $tax->labels->edit_item; 32 32 33 33 if ( ! in_array( $taxonomy, get_taxonomies( array( 'show_ui' => true ) ) ) || 34 ! current_user_can( $tax->cap->manage_terms)34 ! current_user_can( 'edit_term', $tag->term_id ) 35 35 ) { 36 36 wp_die( 37 37 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 38 '<p>' . __( 'Sorry, you are not allowed to managethis item.' ) . '</p>',38 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', 39 39 403 40 40 ); 41 41 } -
src/wp-includes/admin-bar.php
diff --git src/wp-includes/admin-bar.php src/wp-includes/admin-bar.php index 4c4765d..a1bef0d 100644
618 618 ) ); 619 619 } elseif ( ! empty( $current_object->taxonomy ) 620 620 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) 621 && current_user_can( $tax->cap->edit_terms)621 && current_user_can( 'edit_term', $current_object->term_id ) 622 622 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) 623 623 { 624 624 $wp_admin_bar->add_menu( array( -
src/wp-includes/capabilities.php
diff --git src/wp-includes/capabilities.php src/wp-includes/capabilities.php index da54229..67a107b 100644
402 402 case 'delete_site': 403 403 $caps[] = 'manage_options'; 404 404 break; 405 case 'edit_term': 406 case 'delete_term': 407 case 'assign_term': 408 $term_id = $args[0]; 409 $term = get_term( $term_id ); 410 if ( ! $term || is_wp_error( $term ) ) { 411 $caps[] = 'do_not_allow'; 412 break; 413 } 414 415 $tax = get_taxonomy( $term->taxonomy ); 416 if ( ! $tax ) { 417 $caps[] = 'do_not_allow'; 418 break; 419 } 420 421 if ( 'delete_term' === $cap && ( $term->term_id == get_option( 'default_' . $term->taxonomy ) ) ) { 422 $caps[] = 'do_not_allow'; 423 break; 424 } 425 426 $taxo_cap = $cap . 's'; 427 428 $caps = map_meta_cap( $tax->cap->$taxo_cap, $user_id, $term_id ); 429 430 break; 431 case 'manage_categories': 432 case 'manage_post_tags': 433 case 'edit_categories': 434 case 'edit_post_tags': 435 case 'delete_categories': 436 case 'delete_post_tags': 437 $caps[] = 'manage_categories'; 438 break; 439 case 'assign_categories': 440 case 'assign_post_tags': 441 $caps[] = 'edit_posts'; 442 break; 405 443 default: 406 444 // Handle meta capabilities for custom post types. 407 445 global $post_type_meta_caps; -
src/wp-includes/class-wp-xmlrpc-server.php
diff --git src/wp-includes/class-wp-xmlrpc-server.php src/wp-includes/class-wp-xmlrpc-server.php index b08347f..528c74b 100644
1886 1886 1887 1887 $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); 1888 1888 1889 if ( ! current_user_can( $taxonomy->cap-> manage_terms ) )1889 if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { 1890 1890 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) ); 1891 } 1891 1892 1892 1893 $taxonomy = (array) $taxonomy; 1893 1894 … … 1973 1974 1974 1975 $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); 1975 1976 1976 if ( ! current_user_can( $taxonomy->cap->edit_terms ) )1977 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ) );1978 1979 1977 $taxonomy = (array) $taxonomy; 1980 1978 1981 1979 // hold the data of the term … … 1988 1986 1989 1987 if ( ! $term ) 1990 1988 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); 1989 1990 if ( ! current_user_can( 'edit_term', $term_id ) ) { 1991 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this term.' ) ); 1992 } 1991 1993 1992 1994 if ( isset( $content_struct['name'] ) ) { 1993 1995 $term_data['name'] = trim( $content_struct['name'] ); … … 2068 2070 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); 2069 2071 2070 2072 $taxonomy = get_taxonomy( $taxonomy ); 2071 2072 if ( ! current_user_can( $taxonomy->cap->delete_terms ) )2073 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete terms in this taxonomy.' ) );2074 2075 2073 $term = get_term( $term_id, $taxonomy->name ); 2076 2074 2077 2075 if ( is_wp_error( $term ) ) … … 2079 2077 2080 2078 if ( ! $term ) 2081 2079 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); 2080 2081 if ( ! current_user_can( 'delete_term', $term_id ) ) { 2082 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this term.' ) ); 2083 } 2082 2084 2083 2085 $result = wp_delete_term( $term_id, $taxonomy->name ); 2084 2086 … … 2140 2142 2141 2143 $taxonomy = get_taxonomy( $taxonomy ); 2142 2144 2143 if ( ! current_user_can( $taxonomy->cap->assign_terms ) )2144 return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) );2145 2146 2145 $term = get_term( $term_id , $taxonomy->name, ARRAY_A ); 2147 2146 2148 2147 if ( is_wp_error( $term ) ) … … 2151 2150 if ( ! $term ) 2152 2151 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); 2153 2152 2153 if ( ! current_user_can( 'assign_term', $term_id ) ) { 2154 return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign this term.' ) ); 2155 } 2156 2154 2157 return $this->_prepare_term( $term ); 2155 2158 } 2156 2159 -
src/wp-includes/link-template.php
diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php index 292c98c..c1ec8b3 100644
930 930 } 931 931 932 932 $tax = get_taxonomy( $term->taxonomy ); 933 if ( ! $tax || ! current_user_can( $tax->cap->edit_terms) ) {933 if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) { 934 934 return; 935 935 } 936 936 … … 984 984 return; 985 985 986 986 $tax = get_taxonomy( $term->taxonomy ); 987 if ( ! current_user_can( $tax->cap->edit_terms) ) {987 if ( ! current_user_can( 'edit_term', $term->term_id ) ) { 988 988 return; 989 989 } 990 990 -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index 80e1f84..9266b95 100644
61 61 'show_ui' => true, 62 62 'show_admin_column' => true, 63 63 '_builtin' => true, 64 'capabilities' => array( 65 'manage_terms' => 'manage_categories', 66 'edit_terms' => 'edit_categories', 67 'delete_terms' => 'delete_categories', 68 'assign_terms' => 'assign_categories', 69 ), 64 70 ) ); 65 71 66 72 register_taxonomy( 'post_tag', 'post', array( … … 71 77 'show_ui' => true, 72 78 'show_admin_column' => true, 73 79 '_builtin' => true, 80 'capabilities' => array( 81 'manage_terms' => 'manage_post_tags', 82 'edit_terms' => 'edit_post_tags', 83 'delete_terms' => 'delete_post_tags', 84 'assign_terms' => 'assign_post_tags', 85 ), 74 86 ) ); 75 87 76 88 register_taxonomy( 'nav_menu', 'nav_menu_item', array( -
tests/phpunit/tests/user/capabilities.php
diff --git tests/phpunit/tests/user/capabilities.php tests/phpunit/tests/user/capabilities.php index 48de889..83d12a2 100644
231 231 'customize' => array( 'administrator' ), 232 232 'delete_site' => array( 'administrator' ), 233 233 'add_users' => array( 'administrator' ), 234 235 'edit_categories' => array( 'administrator', 'editor' ), 236 'delete_categories' => array( 'administrator', 'editor' ), 237 'manage_post_tags' => array( 'administrator', 'editor' ), 238 'edit_post_tags' => array( 'administrator', 'editor' ), 239 'delete_post_tags' => array( 'administrator', 'editor' ), 240 241 'assign_categories' => array( 'administrator', 'editor', 'author', 'contributor' ), 242 'assign_post_tags' => array( 'administrator', 'editor', 'author', 'contributor' ), 234 243 ); 235 244 } 236 245 … … 238 247 return array( 239 248 'upload_plugins' => array(), 240 249 'upload_themes' => array(), 250 241 251 'customize' => array( 'administrator' ), 242 252 'delete_site' => array( 'administrator' ), 243 253 'add_users' => array( 'administrator' ), 254 255 'edit_categories' => array( 'administrator', 'editor' ), 256 'delete_categories' => array( 'administrator', 'editor' ), 257 'manage_post_tags' => array( 'administrator', 'editor' ), 258 'edit_post_tags' => array( 'administrator', 'editor' ), 259 'delete_post_tags' => array( 'administrator', 'editor' ), 260 261 'assign_categories' => array( 'administrator', 'editor', 'author', 'contributor' ), 262 'assign_post_tags' => array( 'administrator', 'editor', 'author', 'contributor' ), 244 263 ); 245 264 } 246 265 … … 972 991 } 973 992 } 974 993 994 /** 995 * @dataProvider dataTaxonomies 996 * 997 * @ticket 35614 998 */ 999 public function test_default_taxonomy_term_cannot_be_deleted( $taxonomy ) { 1000 if ( ! taxonomy_exists( $taxonomy ) ) { 1001 register_taxonomy( $taxonomy, 'post' ); 1002 } 1003 1004 $tax = get_taxonomy( $taxonomy ); 1005 $user = self::$users['administrator']; 1006 $term = self::factory()->term->create_and_get( array( 1007 'taxonomy' => $taxonomy, 1008 ) ); 1009 1010 update_option( "default_{$taxonomy}", $term->term_id ); 1011 1012 $this->assertTrue( user_can( $user->ID, $tax->cap->delete_terms ) ); 1013 $this->assertFalse( user_can( $user->ID, 'delete_term', $term->term_id ) ); 1014 } 1015 1016 /** 1017 * @dataProvider dataTaxonomies 1018 * 1019 * @ticket 35614 1020 */ 1021 public function test_taxonomy_caps_map_correctly_to_their_meta_cap( $taxonomy ) { 1022 if ( ! taxonomy_exists( $taxonomy ) ) { 1023 register_taxonomy( $taxonomy, 'post' ); 1024 } 1025 1026 $tax = get_taxonomy( $taxonomy ); 1027 $term = self::factory()->term->create_and_get( array( 1028 'taxonomy' => $taxonomy, 1029 ) ); 1030 1031 foreach ( self::$users as $role => $user ) { 1032 $this->assertSame( 1033 user_can( $user->ID, 'edit_term', $term->term_id ), 1034 user_can( $user->ID, $tax->cap->edit_terms ), 1035 "Role: {$role}" 1036 ); 1037 $this->assertSame( 1038 user_can( $user->ID, 'delete_term', $term->term_id ), 1039 user_can( $user->ID, $tax->cap->delete_terms ), 1040 "Role: {$role}" 1041 ); 1042 $this->assertSame( 1043 user_can( $user->ID, 'assign_term', $term->term_id ), 1044 user_can( $user->ID, $tax->cap->assign_terms ), 1045 "Role: {$role}" 1046 ); 1047 } 1048 1049 } 1050 975 1051 public function dataTaxonomies() { 976 1052 return array( 977 1053 array( -
tests/phpunit/tests/xmlrpc/wp/deleteTerm.php
diff --git tests/phpunit/tests/xmlrpc/wp/deleteTerm.php tests/phpunit/tests/xmlrpc/wp/deleteTerm.php index 6f738b1..1132095 100644
43 43 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) ); 44 44 $this->assertInstanceOf( 'IXR_Error', $result ); 45 45 $this->assertEquals( 401, $result->code ); 46 $this->assertEquals( __( 'Sorry, you are not allowed to delete t erms in this taxonomy.' ), $result->message );46 $this->assertEquals( __( 'Sorry, you are not allowed to delete this term.' ), $result->message ); 47 47 } 48 48 49 49 function test_empty_term() { -
tests/phpunit/tests/xmlrpc/wp/editTerm.php
diff --git tests/phpunit/tests/xmlrpc/wp/editTerm.php tests/phpunit/tests/xmlrpc/wp/editTerm.php index af8bd0b..db14a68 100644
49 49 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'category' ) ) ); 50 50 $this->assertInstanceOf( 'IXR_Error', $result ); 51 51 $this->assertEquals( 401, $result->code ); 52 $this->assertEquals( __( 'Sorry, you are not allowed to edit t erms in this taxonomy.' ), $result->message );52 $this->assertEquals( __( 'Sorry, you are not allowed to edit this term.' ), $result->message ); 53 53 } 54 54 55 55 function test_term_not_exists() { -
tests/phpunit/tests/xmlrpc/wp/getTerm.php
diff --git tests/phpunit/tests/xmlrpc/wp/getTerm.php tests/phpunit/tests/xmlrpc/wp/getTerm.php index 3e7257b..627a88d 100644
43 43 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) ); 44 44 $this->assertInstanceOf( 'IXR_Error', $result ); 45 45 $this->assertEquals( 401, $result->code ); 46 $this->assertEquals( __( 'Sorry, you are not allowed to assign t erms in this taxonomy.' ), $result->message );46 $this->assertEquals( __( 'Sorry, you are not allowed to assign this term.' ), $result->message ); 47 47 } 48 48 49 49
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)