3 * Edit Link Categories Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 // Handle bulk actions
13 if ( isset($_GET['action']) && isset($_GET['delete']) ) {
14 check_admin_referer('bulk-link-categories');
15 $doaction = $_GET['action'] ? $_GET['action'] : $_GET['action2'];
17 if ( !current_user_can('manage_categories') )
18 wp_die(__('Cheatin’ uh?'));
20 if ( 'delete' == $doaction ) {
21 foreach( (array) $_GET['delete'] as $cat_ID ) {
22 $cat_name = get_term_field('name', $cat_ID, 'link_category');
23 $default_cat_id = get_option('default_link_category');
25 // Don't delete the default cats.
26 if ( $cat_ID == $default_cat_id )
27 wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
29 wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
32 $location = 'edit-link-categories.php';
33 if ( $referer = wp_get_referer() ) {
34 if ( false !== strpos($referer, 'edit-link-categories.php') )
38 $location = add_query_arg('message', 6, $location);
39 wp_redirect($location);
42 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
43 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
47 $title = __('Link Categories');
49 wp_enqueue_script('admin-categories');
50 if ( current_user_can('manage_categories') )
51 wp_enqueue_script('inline-edit-tax');
53 require_once ('admin-header.php');
55 $messages[1] = __('Category added.');
56 $messages[2] = __('Category deleted.');
57 $messages[3] = __('Category updated.');
58 $messages[4] = __('Category not added.');
59 $messages[5] = __('Category not updated.');
60 $messages[6] = __('Categories deleted.'); ?>
62 <div class="wrap nosubsub">
63 <?php screen_icon(); ?>
64 <h2><?php echo esc_html( $title );
65 if ( isset($_GET['s']) && $_GET['s'] )
66 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
69 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
70 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
71 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
74 <form class="search-form" action="" method="get">
75 <p class="search-box">
76 <label class="screen-reader-text" for="link-category-search-input"><?php _e( 'Search Categories' ); ?>:</label>
77 <input type="text" id="link-category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
78 <input type="submit" value="<?php esc_attr_e( 'Search Categories' ); ?>" class="button" />
83 <div id="col-container">
86 <div class="col-wrap">
87 <form id="posts-filter" action="" method="get">
88 <div class="tablenav">
91 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
92 if ( empty($pagenum) )
94 if( ! isset( $catsperpage ) || $catsperpage < 0 )
97 $page_links = paginate_links( array(
98 'base' => add_query_arg( 'pagenum', '%#%' ),
100 'prev_text' => __('«'),
101 'next_text' => __('»'),
102 'total' => ceil(wp_count_terms('link_category') / $catsperpage),
103 'current' => $pagenum
107 echo "<div class='tablenav-pages'>$page_links</div>";
110 <div class="alignleft actions">
111 <select name="action">
112 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
113 <option value="delete"><?php _e('Delete'); ?></option>
115 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
116 <?php wp_nonce_field('bulk-link-categories'); ?>
122 <div class="clear"></div>
124 <table class="widefat fixed" cellspacing="0">
127 <?php print_column_headers('edit-link-categories'); ?>
133 <?php print_column_headers('edit-link-categories', false); ?>
137 <tbody id="the-list" class="list:link-cat">
139 $start = ($pagenum - 1) * $catsperpage;
140 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
141 if ( !empty( $_GET['s'] ) )
142 $args['search'] = $_GET['s'];
144 $categories = get_terms( 'link_category', $args );
147 foreach ( $categories as $category ) {
148 $output .= link_cat_row($category);
158 <div class="tablenav">
161 echo "<div class='tablenav-pages'>$page_links</div>";
164 <div class="alignleft actions">
165 <select name="action2">
166 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
167 <option value="delete"><?php _e('Delete'); ?></option>
169 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
177 <div class="form-wrap">
178 <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>
183 </div><!-- /col-right -->
186 <div class="col-wrap">
188 <?php if ( current_user_can('manage_categories') ) {
189 $category = (object) array(); $category->parent = 0; do_action('add_link_category_form_pre', $category); ?>
191 <div class="form-wrap">
192 <h3><?php _e('Add Link Category'); ?></h3>
193 <div id="ajax-response"></div>
194 <form name="addcat" id="addcat" class="add:the-list: validate" method="post" action="link-category.php">
195 <input type="hidden" name="action" value="addcat" />
196 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-link-category'); ?>
198 <div class="form-field form-required">
199 <label for="name"><?php _e('Link Category name') ?></label>
200 <input name="name" id="name" type="text" value="" size="40" aria-required="true" />
203 <div class="form-field">
204 <label for="slug"><?php _e('Link Category slug') ?></label>
205 <input name="slug" id="slug" type="text" value="" size="40" />
206 <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>
209 <div class="form-field">
210 <label for="description"><?php _e('Description (optional)') ?></label>
211 <textarea name="description" id="description" rows="5" cols="40"></textarea>
214 <p class="submit"><input type="submit" class="button" name="submit" value="<?php esc_attr_e('Add Category'); ?>" /></p>
215 <?php do_action('edit_link_category_form', $category); ?>
222 </div><!-- /col-left -->
224 </div><!-- /col-container -->
227 <?php inline_edit_term_row('edit-link-categories'); ?>
228 <?php include('admin-footer.php'); ?>