2 require_once('admin.php');
5 if ( isset($_GET['deleteit']) && isset($_GET['delete']) ) {
6 check_admin_referer('bulk-link-categories');
8 if ( !current_user_can('manage_categories') )
9 wp_die(__('Cheatin’ uh?'));
11 foreach( (array) $_GET['delete'] as $cat_ID ) {
12 $cat_name = get_term_field('name', $cat_ID, 'link_category');
13 $default_cat_id = get_option('default_link_category');
15 // Don't delete the default cats.
16 if ( $cat_ID == $default_cat_id )
17 wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
19 wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
22 $location = 'edit-link-categories.php';
23 if ( $referer = wp_get_referer() ) {
24 if ( false !== strpos($referer, 'edit-link-categories.php') )
28 $location = add_query_arg('message', 6, $location);
29 wp_redirect($location);
31 } elseif ( !empty($_GET['_wp_http_referer']) ) {
32 wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
36 $title = __('Link Categories');
37 $parent_file = 'edit.php';
39 wp_enqueue_script( 'admin-categories' );
40 wp_enqueue_script('admin-forms');
42 require_once ('admin-header.php');
44 $messages[1] = __('Category added.');
45 $messages[2] = __('Category deleted.');
46 $messages[3] = __('Category updated.');
47 $messages[4] = __('Category not added.');
48 $messages[5] = __('Category not updated.');
49 $messages[6] = __('Categories deleted.');
51 if (isset($_GET['message'])) : ?>
52 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
53 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
58 <form id="posts-filter" action="" method="get">
59 <?php if ( current_user_can('manage_categories') ) : ?>
60 <h2><?php printf(__('Manage Link Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
62 <h2><?php _e('Manage Link Categories') ?> </h2>
66 <label class="hidden" for="post-search-input"><?php _e( 'Search Categories' ); ?>:</label>
67 <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
68 <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
73 <div class="tablenav">
76 $pagenum = absint( $_GET['pagenum'] );
77 if ( empty($pagenum) )
79 if( !$catsperpage || $catsperpage < 0 )
82 $page_links = paginate_links( array(
83 'base' => add_query_arg( 'pagenum', '%#%' ),
85 'total' => ceil(wp_count_terms('link_category') / $catsperpage),
90 echo "<div class='tablenav-pages'>$page_links</div>";
93 <div class="alignleft">
94 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
95 <?php wp_nonce_field('bulk-link-categories'); ?>
103 <table class="widefat">
106 <th scope="col" class="check-column"><input type="checkbox" /></th>
107 <th scope="col"><?php _e('Name') ?></th>
108 <th scope="col"><?php _e('Description') ?></th>
109 <th scope="col" class="num" style="width: 90px;"><?php _e('Links') ?></th>
112 <tbody id="the-list" class="list:link-cat">
114 $start = ($pagenum - 1) * $catsperpage;
115 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
116 if ( !empty( $_GET['s'] ) )
117 $args['search'] = $_GET['s'];
119 $categories = get_terms( 'link_category', $args );
122 foreach ( $categories as $category ) {
123 $category = sanitize_term($category, 'link_category', 'display');
124 $output .= link_cat_row($category);
126 $output = apply_filters('cat_rows', $output);
136 <div class="tablenav">
140 echo "<div class='tablenav-pages'>$page_links</div>";
148 <?php if ( current_user_can('manage_categories') ) : ?>
150 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the links in that category. Instead, links that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), get_term_field('name', get_option('default_link_category'), 'link_category')) ?></p>
153 <?php include('edit-link-category-form.php'); ?>
157 <?php include('admin-footer.php'); ?>