Make WordPress Core


Ignore:
Timestamp:
08/11/2010 09:54:51 PM (16 years ago)
Author:
scribu
Message:

Ajaxify list-type screens in the admin. See #14579

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-tags.php

    r15441 r15491  
    1010require_once('./admin.php');
    1111
    12 wp_reset_vars( array('action', 'tag', 'taxonomy', 'post_type') );
    13 
    14 if ( empty($taxonomy) )
    15         $taxonomy = 'post_tag';
    16 
    17 if ( !taxonomy_exists($taxonomy) )
    18         wp_die(__('Invalid taxonomy'));
    19 
    20 $tax = get_taxonomy($taxonomy);
    21 
    22 if ( ! current_user_can($tax->cap->manage_terms) )
    23         wp_die(__('Cheatin’ uh?'));
     12require_once( './includes/default-list-tables.php' );
     13
     14$table = new WP_Terms_Table;
    2415
    2516$title = $tax->labels->name;
    26 
    27 if ( empty($post_type) || !in_array( $post_type, get_post_types( array('public' => true) ) ) )
    28         $post_type = 'post';
    2917
    3018if ( 'post' != $post_type ) {
     
    3624}
    3725
    38 if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
     26if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
    3927        $action = 'bulk-delete';
    4028
    41 switch($action) {
     29switch ( $action ) {
    4230
    4331case 'add-tag':
    4432
    45         check_admin_referer('add-tag');
    46 
    47         if ( !current_user_can($tax->cap->edit_terms) )
    48                 wp_die(__('Cheatin’ uh?'));
    49 
    50         $ret = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST);
     33        check_admin_referer( 'add-tag' );
     34
     35        if ( !current_user_can( $tax->cap->edit_terms ) )
     36                wp_die( __( 'Cheatin’ uh?' ) );
     37
     38        $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
    5139        $location = 'edit-tags.php?taxonomy=' . $taxonomy;
    5240        if ( 'post' != $post_type )
     
    5442
    5543        if ( $referer = wp_get_original_referer() ) {
    56                 if ( false !== strpos($referer, 'edit-tags.php') )
     44                if ( false !== strpos( $referer, 'edit-tags.php' ) )
    5745                        $location = $referer;
    5846        }
    5947
    6048        if ( $ret && !is_wp_error( $ret ) )
    61                 $location = add_query_arg('message', 1, $location);
    62         else
    63                 $location = add_query_arg('message', 4, $location);
    64         wp_redirect($location);
     49                $location = add_query_arg( 'message', 1, $location );
     50        else
     51                $location = add_query_arg( 'message', 4, $location );
     52        wp_redirect( $location );
    6553        exit;
    6654break;
     
    7159                $location .= '&post_type=' . $post_type;
    7260        if ( $referer = wp_get_referer() ) {
    73                 if ( false !== strpos($referer, 'edit-tags.php') )
     61                if ( false !== strpos( $referer, 'edit-tags.php' ) )
    7462                        $location = $referer;
    7563        }
    7664
    77         if ( !isset( $_GET['tag_ID'] ) ) {
    78                 wp_redirect($location);
     65        if ( !isset( $_REQUEST['tag_ID'] ) ) {
     66                wp_redirect( $location );
    7967                exit;
    8068        }
    8169
    82         $tag_ID = (int) $_GET['tag_ID'];
    83         check_admin_referer('delete-tag_' .  $tag_ID);
    84 
    85         if ( !current_user_can($tax->cap->delete_terms) )
    86                 wp_die(__('Cheatin’ uh?'));
    87 
    88         wp_delete_term( $tag_ID, $taxonomy);
    89 
    90         $location = add_query_arg('message', 2, $location);
    91         wp_redirect($location);
     70        $tag_ID = (int) $_REQUEST['tag_ID'];
     71        check_admin_referer( 'delete-tag_' .  $tag_ID );
     72
     73        if ( !current_user_can( $tax->cap->delete_terms ) )
     74                wp_die( __( 'Cheatin’ uh?' ) );
     75
     76        wp_delete_term( $tag_ID, $taxonomy );
     77
     78        $location = add_query_arg( 'message', 2, $location );
     79        wp_redirect( $location );
    9280        exit;
    9381
     
    9583
    9684case 'bulk-delete':
    97         check_admin_referer('bulk-tags');
    98 
    99         if ( !current_user_can($tax->cap->delete_terms) )
    100                 wp_die(__('Cheatin’ uh?'));
    101 
    102         $tags = (array) $_GET['delete_tags'];
    103         foreach( $tags as $tag_ID ) {
    104                 wp_delete_term( $tag_ID, $taxonomy);
     85        check_admin_referer( 'bulk-tags' );
     86
     87        if ( !current_user_can( $tax->cap->delete_terms ) )
     88                wp_die( __( 'Cheatin’ uh?' ) );
     89
     90        $tags = (array) $_REQUEST['delete_tags'];
     91        foreach ( $tags as $tag_ID ) {
     92                wp_delete_term( $tag_ID, $taxonomy );
    10593        }
    10694
     
    10997                $location .= '&post_type=' . $post_type;
    11098        if ( $referer = wp_get_referer() ) {
    111                 if ( false !== strpos($referer, 'edit-tags.php') )
     99                if ( false !== strpos( $referer, 'edit-tags.php' ) )
    112100                        $location = $referer;
    113101        }
    114102
    115         $location = add_query_arg('message', 6, $location);
    116         wp_redirect($location);
     103        $location = add_query_arg( 'message', 6, $location );
     104        wp_redirect( $location );
    117105        exit;
    118106
     
    122110        $title = $tax->labels->edit_item;
    123111
    124         require_once ('admin-header.php');
    125         $tag_ID = (int) $_GET['tag_ID'];
    126 
    127         if ( !current_user_can($tax->cap->edit_terms) )
    128                 wp_die( __('You are not allowed to edit this item.') );
    129 
    130         $tag = get_term($tag_ID, $taxonomy, OBJECT, 'edit');
    131         include('./edit-tag-form.php');
     112        require_once ( 'admin-header.php' );
     113        $tag_ID = (int) $_REQUEST['tag_ID'];
     114
     115        $tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' );
     116        include( './edit-tag-form.php' );
    132117
    133118break;
     
    135120case 'editedtag':
    136121        $tag_ID = (int) $_POST['tag_ID'];
    137         check_admin_referer('update-tag_' . $tag_ID);
    138 
    139         if ( !current_user_can($tax->cap->edit_terms) )
    140                 wp_die(__('Cheatin’ uh?'));
    141 
    142         $ret = wp_update_term($tag_ID, $taxonomy, $_POST);
     122        check_admin_referer( 'update-tag_' . $tag_ID );
     123
     124        if ( !current_user_can( $tax->cap->edit_terms ) )
     125                wp_die( __( 'Cheatin’ uh?' ) );
     126
     127        $ret = wp_update_term( $tag_ID, $taxonomy, $_POST );
    143128
    144129        $location = 'edit-tags.php?taxonomy=' . $taxonomy;
     
    147132
    148133        if ( $referer = wp_get_original_referer() ) {
    149                 if ( false !== strpos($referer, 'edit-tags.php') )
     134                if ( false !== strpos( $referer, 'edit-tags.php' ) )
    150135                        $location = $referer;
    151136        }
    152137
    153138        if ( $ret && !is_wp_error( $ret ) )
    154                 $location = add_query_arg('message', 3, $location);
    155         else
    156                 $location = add_query_arg('message', 5, $location);
    157 
    158         wp_redirect($location);
     139                $location = add_query_arg( 'message', 3, $location );
     140        else
     141                $location = add_query_arg( 'message', 5, $location );
     142
     143        wp_redirect( $location );
    159144        exit;
    160145break;
     
    162147default:
    163148
    164 if ( ! empty($_GET['_wp_http_referer']) ) {
     149if ( ! empty($_REQUEST['_wp_http_referer']) ) {
    165150         wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
    166151         exit;
     
    209194
    210195require_once ('admin-header.php');
     196
     197if ( !current_user_can($tax->cap->edit_terms) )
     198        wp_die( __('You are not allowed to edit this item.') );
    211199
    212200$messages[1] = __('Item added.');
     
    222210<?php screen_icon(); ?>
    223211<h2><?php echo esc_html( $title );
    224 if ( !empty($_GET['s']) )
    225         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
     212if ( !empty($_REQUEST['s']) )
     213        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
    226214</h2>
    227215
    228 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
     216<?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
    229217<div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
    230218<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
     
    247235<div id="col-right">
    248236<div class="col-wrap">
    249 <form id="posts-filter" action="" method="get">
     237<form id="posts-filter" action="" method="post">
    250238<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
    251239<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
    252 <div class="tablenav">
    253 <?php
    254 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
    255 if ( empty($pagenum) )
    256         $pagenum = 1;
    257 
    258 $tags_per_page = (int) get_user_option( 'edit_' .  $taxonomy . '_per_page' );
    259 
    260 if ( empty($tags_per_page) || $tags_per_page < 1 )
    261         $tags_per_page = 20;
    262 
    263 if ( 'post_tag' == $taxonomy ) {
    264         $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
    265         $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
    266 } elseif ( 'category' == $taxonomy ) {
    267         $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
    268 } else {
    269         $tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page );
    270 }
    271 
    272 $searchterms = !empty($_GET['s']) ? trim(stripslashes($_GET['s'])) : '';
    273 
    274 $page_links = paginate_links( array(
    275         'base' => add_query_arg( 'pagenum', '%#%' ),
    276         'format' => '',
    277         'prev_text' => __('&laquo;'),
    278         'next_text' => __('&raquo;'),
    279         'total' => ceil(wp_count_terms($taxonomy, array('search' => $searchterms)) / $tags_per_page),
    280         'current' => $pagenum
    281 ));
    282 
    283 if ( $page_links )
    284         echo "<div class='tablenav-pages'>$page_links</div>";
    285 ?>
    286 
    287 <div class="alignleft actions">
    288 <select name="action">
    289 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
    290 <option value="delete"><?php _e('Delete'); ?></option>
    291 </select>
    292 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
    293 <?php wp_nonce_field('bulk-tags'); ?>
    294 </div>
    295 
    296 <br class="clear" />
    297 </div>
    298 
    299 <div class="clear"></div>
    300 <table class="widefat tag fixed" cellspacing="0">
    301         <thead>
    302         <tr>
    303 <?php print_column_headers($current_screen); ?>
    304         </tr>
    305         </thead>
    306 
    307         <tfoot>
    308         <tr>
    309 <?php print_column_headers($current_screen, false); ?>
    310         </tr>
    311         </tfoot>
    312 
    313         <tbody id="the-list" class="list:tag">
    314 <?php tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy ); ?>
    315         </tbody>
    316 </table>
    317 
    318 <div class="tablenav">
    319 <?php
    320 if ( $page_links )
    321         echo "<div class='tablenav-pages'>$page_links</div>";
    322 ?>
    323 
    324 <div class="alignleft actions">
    325 <select name="action2">
    326 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
    327 <option value="delete"><?php _e('Delete'); ?></option>
    328 </select>
    329 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
    330 </div>
    331 
    332 <br class="clear" />
    333 </div>
     240
     241<?php $table->display_table(); ?>
    334242
    335243<br class="clear" />
     
    359267<?php
    360268
    361 if ( !is_taxonomy_hierarchical($taxonomy) ) {
     269if ( !is_null( $tax->labels->popular_items ) ) {
    362270        if ( current_user_can( $tax->cap->edit_terms ) )
    363271                $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
     
    441349</div><!-- /wrap -->
    442350
    443 <?php inline_edit_term_row('edit-tags', $taxonomy); ?>
     351<?php $table->inline_edit(); ?>
    444352
    445353<?php
Note: See TracChangeset for help on using the changeset viewer.