Make WordPress Core

Changeset 12833


Ignore:
Timestamp:
01/26/2010 11:32:04 AM (15 years ago)
Author:
dd32
Message:

First scratch at Taxonomy Capabilities. See #12035

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r12818 r12833  
    205205    $taxonomy = get_taxonomy(substr($action, 4));
    206206    check_ajax_referer( $action );
    207     if ( !current_user_can( 'manage_categories' ) )
     207    if ( !current_user_can( $taxonomy->manage_cap ) )
    208208        die('-1');
    209209    $names = explode(',', $_POST['new'.$taxonomy->name]);
     
    330330    $tag_id = (int) $_POST['tag_ID'];
    331331    check_ajax_referer( "delete-tag_$tag_id" );
    332     if ( !current_user_can( 'manage_categories' ) )
    333         die('-1');
    334332
    335333    $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
     334    $tax = get_taxonomy($taxonomy);
     335
     336    if ( !current_user_can( $tax->delete_cap ) )
     337        die('-1');
    336338
    337339    $tag = get_term( $tag_id, $taxonomy );
     
    600602case 'add-tag' : // From Manage->Tags
    601603    check_ajax_referer( 'add-tag' );
    602     if ( !current_user_can( 'manage_categories' ) )
    603         die('-1');
    604604
    605605    $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
     606    $tax = get_taxonomy($taxonomy);
     607
     608    if ( !current_user_can( $tax->edit_cap ) )
     609        die('-1');
     610
    606611    $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
    607612
     
    11761181    check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
    11771182
    1178     if ( ! current_user_can('manage_categories') )
     1183    $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : false;
     1184    if ( ! $taxonomy )
     1185        die( __('Cheatin’ uh?') );
     1186    $tax = get_taxonomy($taxonomy);
     1187       
     1188    if ( ! current_user_can( $tax->edit_cap ) )
    11791189        die( __('Cheatin’ uh?') );
    11801190
  • trunk/wp-admin/edit-form-advanced.php

    r12798 r12833  
    9898    $label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
    9999
     100    if ( !current_user_can($taxonomy->manage_cap) )
     101        continue;
     102
    100103    if ( !is_taxonomy_hierarchical($tax_name) )
    101104        add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core');
    102105    else
    103         add_meta_box($tax_name.'div', $label, 'post_categories_meta_box', 'post', 'side', 'core', array( 'taxonomy' => $tax_name ));
     106        add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', 'post', 'side', 'core', array( 'taxonomy' => $tax_name ));
    104107}
    105108
  • trunk/wp-admin/edit-tags.php

    r12818 r12833  
    1919if ( !is_taxonomy($taxonomy) )
    2020    wp_die(__('Invalid taxonomy'));
     21
     22$tax = get_taxonomy($taxonomy);
    2123
    2224if ( empty($post_type) || !in_array( $post_type, get_post_types( array('_show' => true) ) ) )
     
    4042    check_admin_referer('add-tag');
    4143
    42     if ( !current_user_can('manage_categories') )
     44    if ( !current_user_can($tax->edit_cap) )
    4345        wp_die(__('Cheatin’ uh?'));
    4446
     
    6163    check_admin_referer('delete-tag_' .  $tag_ID);
    6264
    63     if ( !current_user_can('manage_categories') )
     65    if ( !current_user_can($tax->delete_cap) )
    6466        wp_die(__('Cheatin’ uh?'));
    6567
     
    8183    check_admin_referer('bulk-tags');
    8284
    83     if ( !current_user_can('manage_categories') )
     85    if ( !current_user_can($tax->delete_cap) )
    8486        wp_die(__('Cheatin’ uh?'));
    8587
     
    116118    check_admin_referer('update-tag_' . $tag_ID);
    117119
    118     if ( !current_user_can('manage_categories') )
     120    if ( !current_user_can($tax->edit_cap) )
    119121        wp_die(__('Cheatin’ uh?'));
    120122
     
    143145}
    144146
    145 $can_manage = current_user_can('manage_categories');
    146 
    147147wp_enqueue_script('admin-tags');
    148 if ( $can_manage )
     148if ( current_user_can($tax->edit_cap) )
    149149    wp_enqueue_script('inline-edit-tax');
    150150
     
    250250
    251251    <tbody id="the-list" class="list:tag">
    252 <?php
    253 
    254 $count = tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy );
    255 ?>
     252<?php tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy ); ?>
    256253    </tbody>
    257254</table>
     
    285282<h3><?php _e('Popular Tags'); ?></h3>
    286283<?php
    287 if ( $can_manage )
     284if ( current_user_can($tax->edit_cap) )
    288285    wp_tag_cloud(array('taxonomy' => $taxonomy, 'link' => 'edit'));
    289286else
     
    292289</div>
    293290
    294 <?php if ( $can_manage ) {
    295     do_action('add_tag_form_pre'); ?>
     291<?php if ( current_user_can($tax->edit_cap) ) {
     292    do_action('add_tag_form_pre', $taxonomy); ?>
    296293
    297294<div class="form-wrap">
     
    328325
    329326<p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php esc_attr_e('Add Tag'); ?>" /></p>
    330 <?php do_action('add_tag_form'); ?>
     327<?php do_action('add_tag_form', $taxonomy); ?>
    331328</form></div>
    332329<?php } ?>
  • trunk/wp-admin/includes/meta-boxes.php

    r12798 r12833  
    240240    $tax_name = esc_attr(substr($box['id'], 8));
    241241    $taxonomy = get_taxonomy($tax_name);
     242    if ( !current_user_can($taxonomy->manage_cap) )
     243        return;
    242244    $helps = isset($taxonomy->helps) ? esc_attr($taxonomy->helps) : __('Separate tags with commas.');
    243245?>
     
    276278        $args = $box['args'];
    277279    extract( wp_parse_args($args, $defaults), EXTR_SKIP );
     280    $tax = get_taxonomy($taxonomy);
     281
     282    if ( !current_user_can($tax->manage_cap) )
     283        return;
    278284    ?>
    279285    <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
     
    295301        </div>
    296302
    297     <?php if ( current_user_can('manage_categories') ) : ?>
     303    <?php if ( current_user_can($tax->edit_cap) ) : ?>
    298304            <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
    299305                <h4><a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
  • trunk/wp-admin/includes/template.php

    r12818 r12833  
    212212function inline_edit_term_row($type, $taxonomy) {
    213213
    214     if ( ! current_user_can( 'manage_categories' ) )
     214    $tax = get_taxonomy($taxonomy);
     215    if ( ! current_user_can( $tax->edit_cap ) )
    215216        return;
    216217
     
    679680        else
    680681            $tagsel = $taxonomy;
     682
     683        $tax = get_taxonomy($taxonomy);
     684
    681685        $count = ( $count > 0 ) ? "<a href='edit.php?$tagsel=$tag->slug'>$count</a>" : $count;
    682686
     
    685689        $qe_data = get_term($tag->term_id, $taxonomy, object, 'edit');
    686690        $edit_link = "edit-tags.php?action=edit&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id";
     691
    687692        $out = '';
    688693        $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
     694
    689695        $columns = get_column_headers('edit-tags');
    690696        $hidden = get_hidden_columns('edit-tags');
     697        $default_term = get_option('default_' . $taxonomy);
    691698        foreach ( $columns as $column_name => $column_display_name ) {
    692699            $class = "class=\"$column_name column-$column_name\"";
     
    700707            switch ($column_name) {
    701708                case 'cb':
    702                     if ( $tag->term_id != get_option('default_' . $taxonomy) )
     709                    if ( current_user_can($tax->delete_cap) && $tag->term_id != $default_term )
    703710                        $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
    704711                    else
     
    708715                    $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $name)) . '">' . $name . '</a></strong><br />';
    709716                    $actions = array();
    710                     $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
    711                     $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
    712                     if ( $tag->term_id != get_option('default_' . $taxonomy) )
     717                    if ( current_user_can($tax->edit_cap) ) {
     718                        $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
     719                        $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
     720                    }
     721                    if ( current_user_can($tax->delete_cap) && $tag->term_id != $default_term )
    713722                        $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>";
    714723
     
    747756        }
    748757
    749         $out .= '</tr>';
     758        $out .= "</tr>\n";
    750759
    751760        return $out;
     
    796805    }
    797806
    798     // filter and send to screen
    799807    echo $out;
    800808    return $count;
     
    11361144
    11371145    <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
    1138         <h4><?php echo $bulk ? ( __( 'Bulk Edit' ) ) : __( 'Quick Edit' ); ?></h4>
     1146        <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
    11391147
    11401148
  • trunk/wp-includes/taxonomy.php

    r12818 r12833  
    1616 */
    1717function create_initial_taxonomies() {
    18     register_taxonomy( 'category', 'post', array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => __('Categories'), 'query_var' => false, 'rewrite' => false) ) ;
    19     register_taxonomy( 'post_tag', 'post', array('hierarchical' => false, 'update_count_callback' => '_update_post_term_count', 'label' => __('Post Tags'), 'query_var' => false, 'rewrite' => false) ) ;
    20     register_taxonomy( 'link_category', 'link', array('hierarchical' => false, 'label' => __('Categories'), 'query_var' => false, 'rewrite' => false) ) ;
     18    register_taxonomy( 'category', 'post', array(   'hierarchical' => true,
     19                                                    'update_count_callback' => '_update_post_term_count',
     20                                                    'label' => __('Categories'),
     21                                                    'query_var' => false,
     22                                                    'rewrite' => false,
     23                                                    'edit_cap' => 'no_priv'
     24                                                ) ) ;
     25
     26    register_taxonomy( 'post_tag', 'post', array(
     27                                                    'hierarchical' => false,
     28                                                    'update_count_callback' => '_update_post_term_count',
     29                                                    'label' => __('Post Tags'),
     30                                                    'query_var' => false,
     31                                                    'rewrite' => false
     32                                                ) ) ;
     33
     34    register_taxonomy( 'link_category', 'link', array(  'hierarchical' => false,
     35                                                        'label' => __('Categories'),
     36                                                        'query_var' => false,
     37                                                        'rewrite' => false
     38                                                    ) ) ;
    2139}
    2240add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
     
    168186    global $wp_taxonomies, $wp_rewrite, $wp;
    169187
    170     if (!is_array($wp_taxonomies))
     188    if ( ! is_array($wp_taxonomies) )
    171189        $wp_taxonomies = array();
    172190
     
    190208        $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=$term");
    191209        $wp_rewrite->add_permastruct($taxonomy, "/{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);
     210    }
     211
     212    foreach ( array('manage_cap', 'edit_cap', 'delete_cap') as $cap ) {
     213        if ( empty($args[$cap]) )
     214            $args[$cap] = 'manage_categories';
    192215    }
    193216
Note: See TracChangeset for help on using the changeset viewer.