From b84023ea338b01a5c688b0739574820f9ea12ae2 Mon Sep 17 00:00:00 2001
From: John Blackbourn ' . __( 'Sorry, you are not allowed to delete this item.' ) . ' ' . __( 'Sorry, you are not allowed to edit this item.' ) . ' ' . __( 'Sorry, you are not allowed to edit this item.' ) . '' . __( 'Cheatin’ uh?' ) . '
' .
'' . __( 'Cheatin’ uh?' ) . '
' .
'' . __( 'Cheatin’ uh?' ) . '
' .
- '
labels->separate_items_with_commas; ?>
+ +labels->no_terms; ?>
diff --git a/wp-admin/term.php b/wp-admin/term.php index dc3f1d5fef..2018ac0415 100644 --- a/wp-admin/term.php +++ b/wp-admin/term.php @@ -31,11 +31,11 @@ $taxonomy = $tax->name; $title = $tax->labels->edit_item; if ( ! in_array( $taxonomy, get_taxonomies( array( 'show_ui' => true ) ) ) || - ! current_user_can( $tax->cap->manage_terms ) + ! current_user_can( 'edit_term', $tag->term_id ) ) { wp_die( '' . __( 'Sorry, you are not allowed to manage this item.' ) . '
', + '' . __( 'Sorry, you are not allowed to edit this item.' ) . '
', 403 ); } diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index d562cc6693..1468e85153 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -635,7 +635,7 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { ) ); } elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) - && current_user_can( $tax->cap->edit_terms ) + && current_user_can( 'edit_term', $current_object->term_id ) && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) { $wp_admin_bar->add_menu( array( diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 15e9ef9870..841fba1488 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -402,6 +402,43 @@ function map_meta_cap( $cap, $user_id ) { case 'delete_site': $caps[] = 'manage_options'; break; + case 'edit_term': + case 'delete_term': + case 'assign_term': + $term_id = $args[0]; + $term = get_term( $term_id ); + if ( ! $term || is_wp_error( $term ) ) { + $caps[] = 'do_not_allow'; + break; + } + + $tax = get_taxonomy( $term->taxonomy ); + if ( ! $tax ) { + $caps[] = 'do_not_allow'; + break; + } + + if ( 'delete_term' === $cap && ( $term->term_id == get_option( 'default_' . $term->taxonomy ) ) ) { + $caps[] = 'do_not_allow'; + break; + } + + $taxo_cap = $cap . 's'; + + $caps = map_meta_cap( $tax->cap->$taxo_cap, $user_id, $term_id ); + + break; + case 'manage_post_tags': + case 'edit_categories': + case 'edit_post_tags': + case 'delete_categories': + case 'delete_post_tags': + $caps[] = 'manage_categories'; + break; + case 'assign_categories': + case 'assign_post_tags': + $caps[] = 'edit_posts'; + break; case 'create_sites': case 'delete_sites': case 'manage_network': diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php index b08347f11c..528c74bf46 100644 --- a/wp-includes/class-wp-xmlrpc-server.php +++ b/wp-includes/class-wp-xmlrpc-server.php @@ -1886,8 +1886,9 @@ class wp_xmlrpc_server extends IXR_Server { $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); - if ( ! current_user_can( $taxonomy->cap->manage_terms ) ) + if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) ); + } $taxonomy = (array) $taxonomy; @@ -1973,9 +1974,6 @@ class wp_xmlrpc_server extends IXR_Server { $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); - if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) - return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ) ); - $taxonomy = (array) $taxonomy; // hold the data of the term @@ -1989,6 +1987,10 @@ class wp_xmlrpc_server extends IXR_Server { if ( ! $term ) return new IXR_Error( 404, __( 'Invalid term ID.' ) ); + if ( ! current_user_can( 'edit_term', $term_id ) ) { + return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this term.' ) ); + } + if ( isset( $content_struct['name'] ) ) { $term_data['name'] = trim( $content_struct['name'] ); @@ -2068,10 +2070,6 @@ class wp_xmlrpc_server extends IXR_Server { return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); $taxonomy = get_taxonomy( $taxonomy ); - - if ( ! current_user_can( $taxonomy->cap->delete_terms ) ) - return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete terms in this taxonomy.' ) ); - $term = get_term( $term_id, $taxonomy->name ); if ( is_wp_error( $term ) ) @@ -2080,6 +2078,10 @@ class wp_xmlrpc_server extends IXR_Server { if ( ! $term ) return new IXR_Error( 404, __( 'Invalid term ID.' ) ); + if ( ! current_user_can( 'delete_term', $term_id ) ) { + return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this term.' ) ); + } + $result = wp_delete_term( $term_id, $taxonomy->name ); if ( is_wp_error( $result ) ) @@ -2140,9 +2142,6 @@ class wp_xmlrpc_server extends IXR_Server { $taxonomy = get_taxonomy( $taxonomy ); - if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) - return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); - $term = get_term( $term_id , $taxonomy->name, ARRAY_A ); if ( is_wp_error( $term ) ) @@ -2151,6 +2150,10 @@ class wp_xmlrpc_server extends IXR_Server { if ( ! $term ) return new IXR_Error( 404, __( 'Invalid term ID.' ) ); + if ( ! current_user_can( 'assign_term', $term_id ) ) { + return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign this term.' ) ); + } + return $this->_prepare_term( $term ); } diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 292c98ca80..c1ec8b33a9 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -930,7 +930,7 @@ function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) { } $tax = get_taxonomy( $term->taxonomy ); - if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) { + if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) { return; } @@ -984,7 +984,7 @@ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $e return; $tax = get_taxonomy( $term->taxonomy ); - if ( ! current_user_can( $tax->cap->edit_terms ) ) { + if ( ! current_user_can( 'edit_term', $term->term_id ) ) { return; } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index a39fa47518..e2a5f81f6c 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -61,6 +61,12 @@ function create_initial_taxonomies() { 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, + 'capabilities' => array( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'edit_categories', + 'delete_terms' => 'delete_categories', + 'assign_terms' => 'assign_categories', + ), ) ); register_taxonomy( 'post_tag', 'post', array( @@ -71,6 +77,12 @@ function create_initial_taxonomies() { 'show_ui' => true, 'show_admin_column' => true, '_builtin' => true, + 'capabilities' => array( + 'manage_terms' => 'manage_post_tags', + 'edit_terms' => 'edit_post_tags', + 'delete_terms' => 'delete_post_tags', + 'assign_terms' => 'assign_post_tags', + ), ) ); register_taxonomy( 'nav_menu', 'nav_menu_item', array( diff --git a/wp-includes/version.php b/wp-includes/version.php index c65064180f..2193f2a468 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38697'; +$wp_version = '4.7-alpha-38698'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.