web/wp-admin/categories.php
changeset 136 bde1974c263b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php
       
     2 /**
       
     3  * Categories Management Panel
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Administration
       
     7  */
       
     8 
       
     9 /** Load WordPress Bootstrap */
       
    10 require_once('admin.php');
       
    11 
       
    12 $title = __('Categories');
       
    13 
       
    14 wp_reset_vars( array('action', 'cat') );
       
    15 
       
    16 if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
       
    17 	$action = 'bulk-delete';
       
    18 
       
    19 switch($action) {
       
    20 
       
    21 case 'addcat':
       
    22 
       
    23 	check_admin_referer('add-category');
       
    24 
       
    25 	if ( !current_user_can('manage_categories') )
       
    26 		wp_die(__('Cheatin&#8217; uh?'));
       
    27 
       
    28 	if ( wp_insert_category($_POST ) )
       
    29 		wp_safe_redirect( add_query_arg( 'message', 1, wp_get_referer() ) . '#addcat' );
       
    30 	else
       
    31 		wp_safe_redirect( add_query_arg( 'message', 4, wp_get_referer() ) . '#addcat' );
       
    32 
       
    33 	exit;
       
    34 break;
       
    35 
       
    36 case 'delete':
       
    37 	if ( !isset( $_GET['cat_ID'] ) ) {
       
    38 		wp_redirect('categories.php');
       
    39 		exit;
       
    40 	}
       
    41 
       
    42 	$cat_ID = (int) $_GET['cat_ID'];
       
    43 	check_admin_referer('delete-category_' .  $cat_ID);
       
    44 
       
    45 	if ( !current_user_can('manage_categories') )
       
    46 		wp_die(__('Cheatin&#8217; uh?'));
       
    47 
       
    48 	// Don't delete the default cats.
       
    49 	if ( $cat_ID == get_option('default_category') )
       
    50 		wp_die( sprintf( __("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), get_cat_name($cat_ID) ) );
       
    51 
       
    52 	wp_delete_category($cat_ID);
       
    53 
       
    54 	wp_safe_redirect( add_query_arg( 'message', 2, wp_get_referer() ) );
       
    55 	exit;
       
    56 
       
    57 break;
       
    58 
       
    59 case 'bulk-delete':
       
    60 	check_admin_referer('bulk-categories');
       
    61 
       
    62 	if ( !current_user_can('manage_categories') )
       
    63 		wp_die( __('You are not allowed to delete categories.') );
       
    64 
       
    65 	$cats = (array) $_GET['delete'];
       
    66 	$default_cat = get_option('default_category');
       
    67 	foreach ( $cats as $cat_ID ) {
       
    68 		$cat_ID = (int) $cat_ID;
       
    69 
       
    70 		// Don't delete the default cat.
       
    71 		if ( $cat_ID == $default_cat )
       
    72 			wp_die( sprintf( __("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), get_cat_name($cat_ID) ) );
       
    73 
       
    74 		wp_delete_category($cat_ID);
       
    75 	}
       
    76 
       
    77 	wp_safe_redirect( wp_get_referer() );
       
    78 	exit;
       
    79 
       
    80 break;
       
    81 case 'edit':
       
    82 
       
    83 	$title = __('Edit Category');
       
    84 
       
    85 	require_once ('admin-header.php');
       
    86 	$cat_ID = (int) $_GET['cat_ID'];
       
    87 	$category = get_category_to_edit($cat_ID);
       
    88 	include('edit-category-form.php');
       
    89 
       
    90 break;
       
    91 
       
    92 case 'editedcat':
       
    93 	$cat_ID = (int) $_POST['cat_ID'];
       
    94 	check_admin_referer('update-category_' . $cat_ID);
       
    95 
       
    96 	if ( !current_user_can('manage_categories') )
       
    97 		wp_die(__('Cheatin&#8217; uh?'));
       
    98 
       
    99 	$location = 'categories.php';
       
   100 	if ( $referer = wp_get_original_referer() ) {
       
   101 		if ( false !== strpos($referer, 'categories.php') )
       
   102 			$location = $referer;
       
   103 	}
       
   104 
       
   105 	if ( wp_update_category($_POST) )
       
   106 		$location = add_query_arg('message', 3, $location);
       
   107 	else
       
   108 		$location = add_query_arg('message', 5, $location);
       
   109 
       
   110 	wp_redirect($location);
       
   111 
       
   112 	exit;
       
   113 break;
       
   114 
       
   115 default:
       
   116 
       
   117 if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
       
   118 	 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
       
   119 	 exit;
       
   120 }
       
   121 
       
   122 wp_enqueue_script('admin-categories');
       
   123 if ( current_user_can('manage_categories') )
       
   124 	wp_enqueue_script('inline-edit-tax');
       
   125 
       
   126 require_once ('admin-header.php');
       
   127 
       
   128 $messages[1] = __('Category added.');
       
   129 $messages[2] = __('Category deleted.');
       
   130 $messages[3] = __('Category updated.');
       
   131 $messages[4] = __('Category not added.');
       
   132 $messages[5] = __('Category not updated.');
       
   133 ?>
       
   134 
       
   135 <div class="wrap nosubsub">
       
   136 <?php screen_icon(); ?>
       
   137 <h2><?php echo esc_html( $title );
       
   138 if ( isset($_GET['s']) && $_GET['s'] )
       
   139 	printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
       
   140 </h2>
       
   141 
       
   142 <?php
       
   143 if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
       
   144 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
       
   145 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
       
   146 endif; ?>
       
   147 
       
   148 <form class="search-form topmargin" action="" method="get">
       
   149 <p class="search-box">
       
   150 	<label class="screen-reader-text" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
       
   151 	<input type="text" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
       
   152 	<input type="submit" value="<?php esc_attr_e( 'Search Categories' ); ?>" class="button" />
       
   153 </p>
       
   154 </form>
       
   155 <br class="clear" />
       
   156 
       
   157 <div id="col-container">
       
   158 
       
   159 <div id="col-right">
       
   160 <div class="col-wrap">
       
   161 <form id="posts-filter" action="" method="get">
       
   162 <div class="tablenav">
       
   163 
       
   164 <?php
       
   165 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
       
   166 if ( empty($pagenum) )
       
   167 	$pagenum = 1;
       
   168 
       
   169 $cats_per_page = (int) get_user_option( 'categories_per_page', 0, false );
       
   170 if ( empty( $cats_per_page ) || $cats_per_page < 1 )
       
   171 	$cats_per_page = 20;
       
   172 $cats_per_page = apply_filters( 'edit_categories_per_page', $cats_per_page );
       
   173 
       
   174 if ( !empty($_GET['s']) )
       
   175 	$num_cats = count(get_categories(array('hide_empty' => 0, 'search' => $_GET['s'])));
       
   176 else
       
   177 	$num_cats = wp_count_terms('category');
       
   178 
       
   179 $page_links = paginate_links( array(
       
   180 	'base' => add_query_arg( 'pagenum', '%#%' ),
       
   181 	'format' => '',
       
   182 	'prev_text' => __('&laquo;'),
       
   183 	'next_text' => __('&raquo;'),
       
   184 	'total' => ceil($num_cats / $cats_per_page),
       
   185 	'current' => $pagenum
       
   186 ));
       
   187 
       
   188 if ( $page_links )
       
   189 	echo "<div class='tablenav-pages'>$page_links</div>";
       
   190 ?>
       
   191 
       
   192 <div class="alignleft actions">
       
   193 <select name="action">
       
   194 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
       
   195 <option value="delete"><?php _e('Delete'); ?></option>
       
   196 </select>
       
   197 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
       
   198 <?php wp_nonce_field('bulk-categories'); ?>
       
   199 </div>
       
   200 
       
   201 <br class="clear" />
       
   202 </div>
       
   203 
       
   204 <div class="clear"></div>
       
   205 
       
   206 <table class="widefat fixed" cellspacing="0">
       
   207 	<thead>
       
   208 	<tr>
       
   209 <?php print_column_headers('categories'); ?>
       
   210 	</tr>
       
   211 	</thead>
       
   212 
       
   213 	<tfoot>
       
   214 	<tr>
       
   215 <?php print_column_headers('categories', false); ?>
       
   216 	</tr>
       
   217 	</tfoot>
       
   218 
       
   219 	<tbody id="the-list" class="list:cat">
       
   220 <?php
       
   221 cat_rows(0, 0, 0, $pagenum, $cats_per_page);
       
   222 ?>
       
   223 	</tbody>
       
   224 </table>
       
   225 
       
   226 <div class="tablenav">
       
   227 <?php
       
   228 if ( $page_links )
       
   229 	echo "<div class='tablenav-pages'>$page_links</div>";
       
   230 ?>
       
   231 
       
   232 <div class="alignleft actions">
       
   233 <select name="action2">
       
   234 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
       
   235 <option value="delete"><?php _e('Delete'); ?></option>
       
   236 </select>
       
   237 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
       
   238 <?php wp_nonce_field('bulk-categories'); ?>
       
   239 </div>
       
   240 
       
   241 <br class="clear" />
       
   242 </div>
       
   243 
       
   244 </form>
       
   245 
       
   246 <div class="form-wrap">
       
   247 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?></p>
       
   248 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'admin.php?import=wp-cat2tag') ?></p>
       
   249 </div>
       
   250 
       
   251 </div>
       
   252 </div><!-- /col-right -->
       
   253 
       
   254 <div id="col-left">
       
   255 <div class="col-wrap">
       
   256 
       
   257 <?php if ( current_user_can('manage_categories') ) { ?>
       
   258 <?php $category = (object) array(); $category->parent = 0; do_action('add_category_form_pre', $category); ?>
       
   259 
       
   260 <div class="form-wrap">
       
   261 <h3><?php _e('Add Category'); ?></h3>
       
   262 <div id="ajax-response"></div>
       
   263 <form name="addcat" id="addcat" method="post" action="categories.php" class="add:the-list: validate">
       
   264 <input type="hidden" name="action" value="addcat" />
       
   265 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-category'); ?>
       
   266 
       
   267 <div class="form-field form-required">
       
   268 	<label for="cat_name"><?php _e('Category Name') ?></label>
       
   269 	<input name="cat_name" id="cat_name" type="text" value="" size="40" aria-required="true" />
       
   270     <p><?php _e('The name is used to identify the category almost everywhere, for example under the post or in the category widget.'); ?></p>
       
   271 </div>
       
   272 
       
   273 <div class="form-field">
       
   274 	<label for="category_nicename"><?php _e('Category Slug') ?></label>
       
   275 	<input name="category_nicename" id="category_nicename" type="text" value="" size="40" />
       
   276     <p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
       
   277 </div>
       
   278 
       
   279 <div class="form-field">
       
   280 	<label for="category_parent"><?php _e('Category Parent') ?></label>
       
   281 	<?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
       
   282     <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
       
   283 </div>
       
   284 
       
   285 <div class="form-field">
       
   286 	<label for="category_description"><?php _e('Description') ?></label>
       
   287 	<textarea name="category_description" id="category_description" rows="5" cols="40"></textarea>
       
   288     <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
       
   289 </div>
       
   290 
       
   291 <p class="submit"><input type="submit" class="button" name="submit" value="<?php esc_attr_e('Add Category'); ?>" /></p>
       
   292 <?php do_action('edit_category_form', $category); ?>
       
   293 </form></div>
       
   294 
       
   295 <?php } ?>
       
   296 
       
   297 </div>
       
   298 </div><!-- /col-left -->
       
   299 
       
   300 </div><!-- /col-container -->
       
   301 </div><!-- /wrap -->
       
   302 
       
   303 <?php
       
   304 inline_edit_term_row('categories');
       
   305 
       
   306 break;
       
   307 }
       
   308 
       
   309 include('admin-footer.php');
       
   310 
       
   311 ?>