From 0ec732b34ae0e60737cc4bdb873683d6b515e6e8 Mon Sep 17 00:00:00 2001 From: dd32 Date: Mon, 22 Feb 2010 08:36:32 +0000 Subject: [PATCH] Introduce assign_cap for Taxonomies, Defaults to 'edit_posts'. Allows for Authors/Contributors to tag/categorise their posts. See #12035 git-svn-id: http://svn.automattic.com/wordpress/trunk@13289 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 2 +- wp-admin/includes/meta-boxes.php | 2 +- wp-admin/includes/template.php | 4 ++-- wp-includes/post.php | 2 +- wp-includes/taxonomy.php | 2 ++ 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 5fbf2a996b..89a0fe283d 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -208,7 +208,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->manage_cap ) ) + if ( !current_user_can( $taxonomy->edit_cap ) ) die('-1'); $names = explode(',', $_POST['new'.$taxonomy->name]); $parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0; diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index aa4341a3f4..3a5744a9b1 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -247,7 +247,7 @@ if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 function post_tags_meta_box($post, $box) { $tax_name = esc_attr(substr($box['id'], 8)); $taxonomy = get_taxonomy($tax_name); - if ( !current_user_can($taxonomy->manage_cap) ) // @todo: Display the terms, do not edit. + if ( !current_user_can($taxonomy->assign_cap) ) // @todo: Display the terms, do not edit. return; $helps = isset($taxonomy->helps) ? esc_attr($taxonomy->helps) : __('Separate tags with commas.'); ?> diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index c3be425063..81a257ca87 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -315,7 +315,7 @@ function wp_terms_checklist($post_id = 0, $args = array()) { $args = array('taxonomy' => $taxonomy); $tax = get_taxonomy($taxonomy); - $args['disabled'] = !current_user_can($tax->manage_cap); + $args['disabled'] = !current_user_can($tax->assign_cap); if ( is_array( $selected_cats ) ) $args['selected_cats'] = $selected_cats; @@ -378,7 +378,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->manage_cap) ) + if ( ! current_user_can($tax->assign_cap) ) $disabled = 'disabled="disabled"'; else $disabled = ''; diff --git a/wp-includes/post.php b/wp-includes/post.php index 824606cf49..87d4aa0c22 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2185,7 +2185,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) { if ( !empty($tax_input) ) { foreach ( $tax_input as $taxonomy => $tags ) { $taxonomy_obj = get_taxonomy($taxonomy); - if ( current_user_can($taxonomy_obj->manage_cap) ) + if ( current_user_can($taxonomy_obj->assign_cap) ) wp_set_post_terms( $post_ID, $tags, $taxonomy ); } } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index c1ee24b967..2a7bb5d427 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -256,6 +256,8 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { if ( empty($args[$cap]) ) $args[$cap] = 'manage_categories'; } + if ( empty($args['assign_cap']) ) + $args['assign_cap'] = 'edit_posts'; if ( empty($args['singular_label']) ) $args['singular_label'] = $args['label'];