Changeset 38698
- Timestamp:
- 09/30/2016 10:39:32 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-tags.php
r38647 r38698 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>' . … … 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>' . … … 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 */ -
trunk/src/wp-admin/includes/ajax-actions.php
r38666 r38698 595 595 check_ajax_referer( "delete-tag_$tag_id" ); 596 596 597 if ( ! current_user_can( 'delete_term', $tag_id ) ) { 598 wp_die( -1 ); 599 } 600 597 601 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; 598 $tax = get_taxonomy($taxonomy);599 600 if ( !current_user_can( $tax->cap->delete_terms ) )601 wp_die( -1 );602 603 602 $tag = get_term( $tag_id, $taxonomy ); 604 603 if ( !$tag || is_wp_error( $tag ) ) … … 797 796 $action = 'add-link-category'; 798 797 check_ajax_referer( $action ); 799 if ( !current_user_can( 'manage_categories' ) ) 800 wp_die( -1 ); 798 $tax = get_taxonomy( 'link_category' ); 799 if ( ! current_user_can( $tax->cap->manage_terms ) ) { 800 wp_die( -1 ); 801 } 801 802 $names = explode(',', wp_unslash( $_POST['newcat'] ) ); 802 803 $x = new WP_Ajax_Response(); … … 1704 1705 wp_die( 0 ); 1705 1706 1706 if ( ! current_user_can( $tax->cap->edit_terms ) ) 1707 wp_die( -1 ); 1707 if ( ! isset( $_POST['tax_ID'] ) || ! ( $id = (int) $_POST['tax_ID'] ) ) { 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 ); -
trunk/src/wp-admin/includes/class-wp-terms-list-table.php
r38672 r38698 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; … … 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 ' '; … … 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 … … 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>', … … 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>', -
trunk/src/wp-admin/includes/meta-boxes.php
r38672 r38698 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> -
trunk/src/wp-admin/term.php
r38069 r38698 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 ); -
trunk/src/wp-includes/admin-bar.php
r38683 r38698 636 636 } elseif ( ! empty( $current_object->taxonomy ) 637 637 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) 638 && current_user_can( $tax->cap->edit_terms)638 && current_user_can( 'edit_term', $current_object->term_id ) 639 639 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) 640 640 { -
trunk/src/wp-includes/capabilities.php
r38695 r38698 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_post_tags': 432 case 'edit_categories': 433 case 'edit_post_tags': 434 case 'delete_categories': 435 case 'delete_post_tags': 436 $caps[] = 'manage_categories'; 437 break; 438 case 'assign_categories': 439 case 'assign_post_tags': 440 $caps[] = 'edit_posts'; 441 break; 405 442 case 'create_sites': 406 443 case 'delete_sites': -
trunk/src/wp-includes/class-wp-xmlrpc-server.php
r38620 r38698 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; … … 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 … … 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'] ) ) { … … 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 … … 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 ); … … 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 … … 2151 2150 if ( ! $term ) 2152 2151 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); 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 } 2153 2156 2154 2157 return $this->_prepare_term( $term ); -
trunk/src/wp-includes/link-template.php
r38645 r38698 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 } … … 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 } -
trunk/src/wp-includes/taxonomy.php
r38677 r38698 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 … … 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 -
trunk/tests/phpunit/tests/user/capabilities.php
r38697 r38698 224 224 'delete_site' => array( 'administrator' ), 225 225 'add_users' => array( 'administrator' ), 226 227 'edit_categories' => array( 'administrator', 'editor' ), 228 'delete_categories' => array( 'administrator', 'editor' ), 229 'manage_post_tags' => array( 'administrator', 'editor' ), 230 'edit_post_tags' => array( 'administrator', 'editor' ), 231 'delete_post_tags' => array( 'administrator', 'editor' ), 232 233 'assign_categories' => array( 'administrator', 'editor', 'author', 'contributor' ), 234 'assign_post_tags' => array( 'administrator', 'editor', 'author', 'contributor' ), 226 235 ); 227 236 } … … 243 252 'delete_site' => array( 'administrator' ), 244 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' ), 245 263 ); 246 264 } … … 400 418 $expected['add_post_meta'], 401 419 $expected['edit_comment'], 420 $expected['edit_term'], 421 $expected['delete_term'], 422 $expected['assign_term'], 402 423 $expected['delete_user'] 403 424 ); … … 1077 1098 ), $caps, "Meta cap: {$meta_cap}" ); 1078 1099 } 1100 } 1101 1102 /** 1103 * @dataProvider dataTaxonomies 1104 * 1105 * @ticket 35614 1106 */ 1107 public function test_default_taxonomy_term_cannot_be_deleted( $taxonomy ) { 1108 if ( ! taxonomy_exists( $taxonomy ) ) { 1109 register_taxonomy( $taxonomy, 'post' ); 1110 } 1111 1112 $tax = get_taxonomy( $taxonomy ); 1113 $user = self::$users['administrator']; 1114 $term = self::factory()->term->create_and_get( array( 1115 'taxonomy' => $taxonomy, 1116 ) ); 1117 1118 update_option( "default_{$taxonomy}", $term->term_id ); 1119 1120 $this->assertTrue( user_can( $user->ID, $tax->cap->delete_terms ) ); 1121 $this->assertFalse( user_can( $user->ID, 'delete_term', $term->term_id ) ); 1122 } 1123 1124 /** 1125 * @dataProvider dataTaxonomies 1126 * 1127 * @ticket 35614 1128 */ 1129 public function test_taxonomy_caps_map_correctly_to_their_meta_cap( $taxonomy ) { 1130 if ( ! taxonomy_exists( $taxonomy ) ) { 1131 register_taxonomy( $taxonomy, 'post' ); 1132 } 1133 1134 $tax = get_taxonomy( $taxonomy ); 1135 $term = self::factory()->term->create_and_get( array( 1136 'taxonomy' => $taxonomy, 1137 ) ); 1138 1139 foreach ( self::$users as $role => $user ) { 1140 $this->assertSame( 1141 user_can( $user->ID, 'edit_term', $term->term_id ), 1142 user_can( $user->ID, $tax->cap->edit_terms ), 1143 "Role: {$role}" 1144 ); 1145 $this->assertSame( 1146 user_can( $user->ID, 'delete_term', $term->term_id ), 1147 user_can( $user->ID, $tax->cap->delete_terms ), 1148 "Role: {$role}" 1149 ); 1150 $this->assertSame( 1151 user_can( $user->ID, 'assign_term', $term->term_id ), 1152 user_can( $user->ID, $tax->cap->assign_terms ), 1153 "Role: {$role}" 1154 ); 1155 } 1156 1079 1157 } 1080 1158 -
trunk/tests/phpunit/tests/xmlrpc/wp/deleteTerm.php
r38078 r38698 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 -
trunk/tests/phpunit/tests/xmlrpc/wp/editTerm.php
r38078 r38698 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 -
trunk/tests/phpunit/tests/xmlrpc/wp/getTerm.php
r38078 r38698 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
Note: See TracChangeset
for help on using the changeset viewer.