Make WordPress Core


Ignore:
Timestamp:
09/30/2016 10:39:32 PM (8 years ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r38672 r38698  
    152152    protected function get_bulk_actions() {
    153153        $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        }
    155158
    156159        return $actions;
     
    333336     */
    334337    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 ) ) {
    338339            return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>'
    339340                . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />';
     341        }
    340342
    341343        return '&nbsp;';
     
    424426        $taxonomy = $this->screen->taxonomy;
    425427        $tax = get_taxonomy( $taxonomy );
    426         $default_term = get_option( 'default_' . $taxonomy );
    427 
    428428        $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
    429429
     
    435435
    436436        $actions = array();
    437         if ( current_user_can( $tax->cap->edit_terms ) ) {
     437        if ( current_user_can( 'edit_term', $tag->term_id ) ) {
    438438            $actions['edit'] = sprintf(
    439439                '<a href="%s" aria-label="%s">%s</a>',
     
    450450            );
    451451        }
    452         if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) {
     452        if ( current_user_can( 'delete_term', $tag->term_id ) ) {
    453453            $actions['delete'] = sprintf(
    454454                '<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>',
Note: See TracChangeset for help on using the changeset viewer.