Allow viewing of Attached hierarchical Terms when the user doesnt have Manage capability of the taxonomy, Only set terms if user has Management capability. See #12035

git-svn-id: https://develop.svn.wordpress.org/trunk@12967 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2010-02-05 14:33:29 +00:00
parent 317b630173
commit b48695661a
2 changed files with 13 additions and 6 deletions

View File

@ -239,7 +239,7 @@ if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0
function post_tags_meta_box($post, $box) { function post_tags_meta_box($post, $box) {
$tax_name = esc_attr(substr($box['id'], 8)); $tax_name = esc_attr(substr($box['id'], 8));
$taxonomy = get_taxonomy($tax_name); $taxonomy = get_taxonomy($tax_name);
if ( !current_user_can($taxonomy->manage_cap) ) if ( !current_user_can($taxonomy->manage_cap) ) // @todo: Display the terms, do not edit.
return; return;
$helps = isset($taxonomy->helps) ? esc_attr($taxonomy->helps) : __('Separate tags with commas.'); $helps = isset($taxonomy->helps) ? esc_attr($taxonomy->helps) : __('Separate tags with commas.');
?> ?>
@ -279,8 +279,6 @@ function post_categories_meta_box( $post, $box ) {
extract( wp_parse_args($args, $defaults), EXTR_SKIP ); extract( wp_parse_args($args, $defaults), EXTR_SKIP );
$tax = get_taxonomy($taxonomy); $tax = get_taxonomy($taxonomy);
if ( !current_user_can($tax->manage_cap) )
return;
?> ?>
<div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
<ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">

View File

@ -474,7 +474,7 @@ class Walker_Category_Checklist extends Walker {
$name = 'tax_input['.$taxonomy.']'; $name = 'tax_input['.$taxonomy.']';
$class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>'; $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . (!empty($args['disabled']) ? 'disabled="disabled"' : '') . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
} }
function end_el(&$output, $category, $depth, $args) { function end_el(&$output, $category, $depth, $args) {
@ -528,6 +528,9 @@ function wp_terms_checklist($post_id = 0, $args = array()) {
$args = array('taxonomy' => $taxonomy); $args = array('taxonomy' => $taxonomy);
$tax = get_taxonomy($taxonomy);
$args['disabled'] = !current_user_can($tax->manage_cap);
if ( is_array( $selected_cats ) ) if ( is_array( $selected_cats ) )
$args['selected_cats'] = $selected_cats; $args['selected_cats'] = $selected_cats;
elseif ( $post_id ) elseif ( $post_id )
@ -588,6 +591,12 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
$terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
$tax = get_taxonomy($taxonomy);
if ( ! current_user_can($tax->manage_cap) )
$disabled = 'disabled="disabled"';
else
$disabled = '';
$popular_ids = array(); $popular_ids = array();
foreach ( (array) $terms as $term ) { foreach ( (array) $terms as $term ) {
$popular_ids[] = $term->term_id; $popular_ids[] = $term->term_id;
@ -599,7 +608,7 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
<li id="<?php echo $id; ?>" class="popular-category"> <li id="<?php echo $id; ?>" class="popular-category">
<label class="selectit"> <label class="selectit">
<input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" /> <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/>
<?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?> <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?>
</label> </label>
</li> </li>