mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Move taxonomy object properties for capabilities into a cap object. Capabilities can be specified via ['capabilities'] (an array keyed by the generic cap name) for register_taxonomy. fixes #13358.
git-svn-id: http://svn.automattic.com/wordpress/trunk@14593 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c6572a1d16
commit
af91e5264a
@ -219,7 +219,7 @@ function _wp_ajax_add_hierarchical_term() {
|
||||
$action = $_POST['action'];
|
||||
$taxonomy = get_taxonomy(substr($action, 4));
|
||||
check_ajax_referer( $action );
|
||||
if ( !current_user_can( $taxonomy->edit_cap ) )
|
||||
if ( !current_user_can( $taxonomy->cap->edit_terms ) )
|
||||
die('-1');
|
||||
$names = explode(',', $_POST['new'.$taxonomy->name]);
|
||||
$parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0;
|
||||
@ -334,7 +334,7 @@ case 'delete-tag' :
|
||||
$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
|
||||
if ( !current_user_can( $tax->delete_cap ) )
|
||||
if ( !current_user_can( $tax->cap->delete_terms ) )
|
||||
die('-1');
|
||||
|
||||
$tag = get_term( $tag_id, $taxonomy );
|
||||
@ -566,7 +566,7 @@ case 'add-tag' : // From Manage->Tags
|
||||
|
||||
$x = new WP_Ajax_Response();
|
||||
|
||||
if ( !current_user_can( $tax->edit_cap ) )
|
||||
if ( !current_user_can( $tax->cap->edit_terms ) )
|
||||
die('-1');
|
||||
|
||||
$tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
|
||||
@ -1204,7 +1204,7 @@ case 'inline-save-tax':
|
||||
die( __('Cheatin’ uh?') );
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
|
||||
if ( ! current_user_can( $tax->edit_cap ) )
|
||||
if ( ! current_user_can( $tax->cap->edit_terms ) )
|
||||
die( __('Cheatin’ uh?') );
|
||||
|
||||
if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
|
||||
|
@ -41,7 +41,7 @@ case 'add-tag':
|
||||
|
||||
check_admin_referer('add-tag');
|
||||
|
||||
if ( !current_user_can($tax->edit_cap) )
|
||||
if ( !current_user_can($tax->cap->edit_terms) )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
$ret = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST);
|
||||
@ -79,7 +79,7 @@ case 'delete':
|
||||
$tag_ID = (int) $_GET['tag_ID'];
|
||||
check_admin_referer('delete-tag_' . $tag_ID);
|
||||
|
||||
if ( !current_user_can($tax->delete_cap) )
|
||||
if ( !current_user_can($tax->cap->delete_terms) )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
wp_delete_term( $tag_ID, $taxonomy);
|
||||
@ -93,7 +93,7 @@ break;
|
||||
case 'bulk-delete':
|
||||
check_admin_referer('bulk-tags');
|
||||
|
||||
if ( !current_user_can($tax->delete_cap) )
|
||||
if ( !current_user_can($tax->cap->delete_terms) )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
$tags = (array) $_GET['delete_tags'];
|
||||
@ -130,7 +130,7 @@ case 'editedtag':
|
||||
$tag_ID = (int) $_POST['tag_ID'];
|
||||
check_admin_referer('update-tag_' . $tag_ID);
|
||||
|
||||
if ( !current_user_can($tax->edit_cap) )
|
||||
if ( !current_user_can($tax->cap->edit_terms) )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
$ret = wp_update_term($tag_ID, $taxonomy, $_POST);
|
||||
@ -161,7 +161,7 @@ if ( ! empty($_GET['_wp_http_referer']) ) {
|
||||
}
|
||||
|
||||
wp_enqueue_script('admin-tags');
|
||||
if ( current_user_can($tax->edit_cap) )
|
||||
if ( current_user_can($tax->cap->edit_terms) )
|
||||
wp_enqueue_script('inline-edit-tax');
|
||||
|
||||
require_once ('admin-header.php');
|
||||
@ -318,7 +318,7 @@ do_action('after-' . $taxonomy . '-table', $taxonomy);
|
||||
<div class="col-wrap">
|
||||
|
||||
<?php
|
||||
if ( current_user_can( $tax->edit_cap ) )
|
||||
if ( current_user_can( $tax->cap->edit_terms ) )
|
||||
$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
|
||||
else
|
||||
$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
|
||||
@ -332,7 +332,7 @@ if ( $tag_cloud ) :
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if ( current_user_can($tax->edit_cap) ) {
|
||||
if ( current_user_can($tax->cap->edit_terms) ) {
|
||||
if ( 'category' == $taxonomy )
|
||||
do_action('add_category_form_pre', (object)array('parent' => 0) ); // Back compat hook. Deprecated in preference to $taxonomy_pre_add_form
|
||||
else
|
||||
|
@ -249,14 +249,14 @@ function post_tags_meta_box($post, $box) {
|
||||
$help_nojs = isset( $taxonomy->help_nojs ) ? $taxonomy->help_nojs : __('Add or remove tags');
|
||||
$help_cloud = isset( $taxonomy->help_cloud ) ? $taxonomy->help_cloud : __('Choose from the most used tags in %s');
|
||||
|
||||
$disabled = !current_user_can($taxonomy->assign_cap) ? 'disabled="disabled"' : '';
|
||||
$disabled = !current_user_can($taxonomy->cap->assign_terms) ? 'disabled="disabled"' : '';
|
||||
?>
|
||||
<div class="tagsdiv" id="<?php echo $tax_name; ?>">
|
||||
<div class="jaxtag">
|
||||
<div class="nojs-tags hide-if-js">
|
||||
<p><?php echo $help_nojs; ?></p>
|
||||
<textarea name="<?php echo "tax_input[$tax_name]"; ?>" class="the-tags" id="tax-input[<?php echo $tax_name; ?>]" <?php echo $disabled; ?>><?php echo esc_attr(get_terms_to_edit( $post->ID, $tax_name )); ?></textarea></div>
|
||||
<?php if ( current_user_can($taxonomy->assign_cap) ) : ?>
|
||||
<?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?>
|
||||
<div class="ajaxtag hide-if-no-js">
|
||||
<label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $box['title']; ?></label>
|
||||
<div class="taghint"><?php echo $help_hint; ?></div>
|
||||
@ -268,7 +268,7 @@ function post_tags_meta_box($post, $box) {
|
||||
</div>
|
||||
<div class="tagchecklist"></div>
|
||||
</div>
|
||||
<?php if ( current_user_can($taxonomy->assign_cap) ) : ?>
|
||||
<?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?>
|
||||
<p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php printf( $help_cloud, $box['title'] ); ?></a></p>
|
||||
<?php else : ?>
|
||||
<p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
|
||||
@ -315,10 +315,10 @@ function post_categories_meta_box( $post, $box ) {
|
||||
<?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php if ( !current_user_can($tax->assign_cap) ) : ?>
|
||||
<?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
|
||||
<p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( current_user_can($tax->edit_cap) ) : ?>
|
||||
<?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
|
||||
<div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
|
||||
<h4><a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"><?php printf( __( '+ Add New %s' ), $tax->singular_label ); ?></a></h4>
|
||||
<p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
|
||||
|
@ -318,7 +318,7 @@ function bulk_edit_posts( $post_data = null ) {
|
||||
|
||||
foreach ( $tax_names as $tax_name ) {
|
||||
$taxonomy_obj = get_taxonomy($tax_name);
|
||||
if( isset( $tax_input[$tax_name]) && current_user_can( $taxonomy_obj->assign_cap ) )
|
||||
if( isset( $tax_input[$tax_name]) && current_user_can( $taxonomy_obj->cap->assign_terms ) )
|
||||
$new_terms = $tax_input[$tax_name];
|
||||
else
|
||||
$new_terms = array();
|
||||
|
@ -22,7 +22,7 @@
|
||||
function inline_edit_term_row($type, $taxonomy) {
|
||||
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
if ( ! current_user_can( $tax->edit_cap ) )
|
||||
if ( ! current_user_can( $tax->cap->edit_terms ) )
|
||||
return;
|
||||
|
||||
$columns = get_column_headers($type);
|
||||
@ -261,7 +261,7 @@ function wp_terms_checklist($post_id = 0, $args = array()) {
|
||||
$args = array('taxonomy' => $taxonomy);
|
||||
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
$args['disabled'] = !current_user_can($tax->assign_cap);
|
||||
$args['disabled'] = !current_user_can($tax->cap->assign_terms);
|
||||
|
||||
if ( is_array( $selected_cats ) )
|
||||
$args['selected_cats'] = $selected_cats;
|
||||
@ -324,7 +324,7 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
|
||||
$terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
|
||||
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
if ( ! current_user_can($tax->assign_cap) )
|
||||
if ( ! current_user_can($tax->cap->assign_terms) )
|
||||
$disabled = 'disabled="disabled"';
|
||||
else
|
||||
$disabled = '';
|
||||
@ -436,7 +436,7 @@ function _tag_row( $tag, $level, $taxonomy = 'post_tag' ) {
|
||||
|
||||
switch ($column_name) {
|
||||
case 'cb':
|
||||
if ( current_user_can($tax->delete_cap) && $tag->term_id != $default_term )
|
||||
if ( current_user_can($tax->cap->delete_terms) && $tag->term_id != $default_term )
|
||||
$out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
|
||||
else
|
||||
$out .= '<th scope="row" class="check-column"> </th>';
|
||||
@ -444,11 +444,11 @@ function _tag_row( $tag, $level, $taxonomy = 'post_tag' ) {
|
||||
case 'name':
|
||||
$out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit “%s”'), $name)) . '">' . $name . '</a></strong><br />';
|
||||
$actions = array();
|
||||
if ( current_user_can($tax->edit_cap) ) {
|
||||
if ( current_user_can($tax->cap->edit_terms) ) {
|
||||
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
|
||||
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick Edit') . '</a>';
|
||||
}
|
||||
if ( current_user_can($tax->delete_cap) && $tag->term_id != $default_term )
|
||||
if ( current_user_can($tax->cap->delete_terms) && $tag->term_id != $default_term )
|
||||
$actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>";
|
||||
|
||||
$actions = apply_filters('tag_row_actions', $actions, $tag);
|
||||
|
@ -89,7 +89,7 @@ $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu
|
||||
if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) )
|
||||
continue;
|
||||
|
||||
$submenu['edit.php'][$i++] = array( esc_attr($tax->label), $tax->manage_cap, 'edit-tags.php?taxonomy=' . $tax->name );
|
||||
$submenu['edit.php'][$i++] = array( esc_attr($tax->label), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name );
|
||||
}
|
||||
unset($tax);
|
||||
|
||||
@ -138,7 +138,7 @@ foreach ( (array) get_post_types( array('show_ui' => true) ) as $ptype ) {
|
||||
if ( ! $tax->show_ui || ! in_array($ptype, (array) $tax->object_type, true) )
|
||||
continue;
|
||||
|
||||
$submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr($tax->label), $tax->manage_cap, "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" );
|
||||
$submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr($tax->label), $tax->cap->manage_terms, "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" );
|
||||
}
|
||||
}
|
||||
unset($ptype, $ptype_obj);
|
||||
|
@ -504,10 +504,10 @@ var photostorage = false;
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php if ( !current_user_can($tax->assign_cap) ) : ?>
|
||||
<?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
|
||||
<p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( current_user_can($tax->edit_cap) ) : ?>
|
||||
<?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
|
||||
<div id="category-adder" class="wp-hidden-children">
|
||||
<h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php printf( __( '+ Add New %s' ), $tax->singular_label ); ?></a></h4>
|
||||
<p id="category-add" class="category-add wp-hidden-child">
|
||||
|
@ -33,7 +33,7 @@ endif;
|
||||
$cats = get_taxonomy('category');
|
||||
$tags = get_taxonomy('post_tag');
|
||||
|
||||
if ( current_user_can($cats->manage_cap) || current_user_can($tags->manage_cap) ) : ?>
|
||||
if ( current_user_can($cats->cap->manage_terms) || current_user_can($tags->cap->manage_terms) ) : ?>
|
||||
<div class="tool-box">
|
||||
<h3 class="title"><?php _e('Category/Tag Conversion') ?></h3>
|
||||
<p><?php printf(__('Use this to convert <a href="%s">categories to tags</a>, or <a href="%s">tags to categories</a>.'), 'admin.php?import=wp-cat2tag', 'admin.php?import=wp-cat2tag&step=3'); ?></p>
|
||||
|
@ -646,7 +646,7 @@ function get_tag_feed_link($tag_id, $feed = '') {
|
||||
function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
|
||||
global $post_type;
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
if ( !current_user_can($tax->edit_cap) )
|
||||
if ( !current_user_can($tax->cap->edit_terms) )
|
||||
return;
|
||||
|
||||
$tag = get_term($tag_id, $taxonomy);
|
||||
@ -668,7 +668,7 @@ function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
|
||||
*/
|
||||
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
|
||||
$tax = get_taxonomy('post_tag');
|
||||
if ( !current_user_can($tax->edit_cap) )
|
||||
if ( !current_user_can($tax->cap->edit_terms) )
|
||||
return;
|
||||
|
||||
$tag = get_term($tag, 'post_tag');
|
||||
|
@ -2329,7 +2329,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
|
||||
$taxonomy_obj = get_taxonomy($taxonomy);
|
||||
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
|
||||
$tags = array_filter($tags);
|
||||
if ( current_user_can($taxonomy_obj->assign_cap) )
|
||||
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
|
||||
wp_set_post_terms( $post_ID, $tags, $taxonomy );
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,8 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
||||
'show_ui' => null,
|
||||
'label' => null,
|
||||
'show_tagcloud' => null,
|
||||
'_builtin' => false
|
||||
'_builtin' => false,
|
||||
'capabilities' => array(),
|
||||
);
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
|
||||
@ -285,12 +286,14 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
||||
if ( is_null($args['label'] ) )
|
||||
$args['label'] = $taxonomy;
|
||||
|
||||
foreach ( array('manage_cap', 'edit_cap', 'delete_cap') as $cap ) {
|
||||
if ( empty($args[$cap]) )
|
||||
$args[$cap] = 'manage_categories';
|
||||
}
|
||||
if ( empty($args['assign_cap']) )
|
||||
$args['assign_cap'] = 'edit_posts';
|
||||
$default_caps = array(
|
||||
'manage_terms' => 'manage_categories',
|
||||
'edit_terms' => 'manage_categories',
|
||||
'delete_terms' => 'manage_categories',
|
||||
'assign_terms' => 'edit_posts',
|
||||
);
|
||||
$args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] );
|
||||
unset( $args['capabilities'] );
|
||||
|
||||
if ( empty($args['singular_label']) )
|
||||
$args['singular_label'] = $args['label'];
|
||||
|
Loading…
Reference in New Issue
Block a user