Taxonomy: Introduce more fine grained capabilities for managing taxonomy terms.
This introduces the singular `edit_term`, `delete_term`, and `assign_term` meta capabilities for terms, and switches the base capability name for tags from `manage_categories` to `manage_post_tags` and the corresponding `edit_post_tags`, `delete_post_tags`, and `assign_post_tags`. All of these capabilities ultimately map to `manage_categories` so by default there is no change in the behaviour of the capabilities for categories, tags, or custom taxonomies. The `map_meta_cap` filter and the `capabilities` argument when registering a taxonomy now allow for control over editing, deleting, and assigning individual terms, as well as a separation of capabilities for tags from those of categories. Fixes #35614 Props johnjamesjacoby for feedback Built from https://develop.svn.wordpress.org/trunk@38698 git-svn-id: http://core.svn.wordpress.org/trunk@38641 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user