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