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 $cats = (array) $_GET['delete'];
22 $default_cat_id = get_option('default_link_category');
24 foreach( $cats as $cat_ID ) {
25 $cat_ID = (int) $cat_ID;
26 // Don't delete the default cats.
27 if ( $cat_ID == $default_cat_id )
28 wp_die( sprintf( __("Can’t delete the <strong>%s</strong> category: this is the default one"), get_term_field('name', $cat_ID, 'link_category') ) );
30 wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
33 $location = 'edit-link-categories.php';
34 if ( $referer = wp_get_referer() ) {
35 if ( false !== strpos($referer, 'edit-link-categories.php') )
39 $location = add_query_arg('message', 6, $location);
40 wp_redirect($location);
43 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
44 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
48 $title = __('Link Categories');
50 wp_enqueue_script('admin-categories');
51 if ( current_user_can('manage_categories') )
52 wp_enqueue_script('inline-edit-tax');
54 require_once ('admin-header.php');
56 $messages[1] = __('Category added.');
57 $messages[2] = __('Category deleted.');
58 $messages[3] = __('Category updated.');
59 $messages[4] = __('Category not added.');
60 $messages[5] = __('Category not updated.');
61 $messages[6] = __('Categories deleted.'); ?>
63 <div class="wrap nosubsub">
64 <?php screen_icon(); ?>
65 <h2><?php echo esc_html( $title );
66 if ( isset($_GET['s']) && $_GET['s'] )
67 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
70 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
71 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
72 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
75 <form class="search-form" action="" method="get">
76 <p class="search-box">
77 <label class="screen-reader-text" for="link-category-search-input"><?php _e( 'Search Categories' ); ?>:</label>
78 <input type="text" id="link-category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
79 <input type="submit" value="<?php esc_attr_e( 'Search Categories' ); ?>" class="button" />
84 <div id="col-container">
87 <div class="col-wrap">
88 <form id="posts-filter" action="" method="get">
89 <div class="tablenav">
92 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
93 if ( empty($pagenum) )
95 if( ! isset( $catsperpage ) || $catsperpage < 0 )
98 $page_links = paginate_links( array(
99 'base' => add_query_arg( 'pagenum', '%#%' ),
101 'prev_text' => __('«'),
102 'next_text' => __('»'),
103 'total' => ceil(wp_count_terms('link_category') / $catsperpage),
104 'current' => $pagenum
108 echo "<div class='tablenav-pages'>$page_links</div>";
111 <div class="alignleft actions">
112 <select name="action">
113 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
114 <option value="delete"><?php _e('Delete'); ?></option>
116 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
117 <?php wp_nonce_field('bulk-link-categories'); ?>
123 <div class="clear"></div>
125 <table class="widefat fixed" cellspacing="0">
128 <?php print_column_headers('edit-link-categories'); ?>
134 <?php print_column_headers('edit-link-categories', false); ?>
138 <tbody id="the-list" class="list:link-cat">
140 $start = ($pagenum - 1) * $catsperpage;
141 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
142 if ( !empty( $_GET['s'] ) )
143 $args['search'] = $_GET['s'];
145 $categories = get_terms( 'link_category', $args );
148 foreach ( $categories as $category ) {
149 $output .= link_cat_row($category);
159 <div class="tablenav">
162 echo "<div class='tablenav-pages'>$page_links</div>";
165 <div class="alignleft actions">
166 <select name="action2">
167 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
168 <option value="delete"><?php _e('Delete'); ?></option>
170 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
178 <div class="form-wrap">
179 <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>
184 </div><!-- /col-right -->
187 <div class="col-wrap">
189 <?php if ( current_user_can('manage_categories') ) {
190 $category = (object) array(); $category->parent = 0; do_action('add_link_category_form_pre', $category); ?>
192 <div class="form-wrap">
193 <h3><?php _e('Add Link Category'); ?></h3>
194 <div id="ajax-response"></div>
195 <form name="addcat" id="addcat" class="add:the-list: validate" method="post" action="link-category.php">
196 <input type="hidden" name="action" value="addcat" />
197 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-link-category'); ?>
199 <div class="form-field form-required">
200 <label for="name"><?php _e('Link Category name') ?></label>
201 <input name="name" id="name" type="text" value="" size="40" aria-required="true" />
204 <div class="form-field">
205 <label for="slug"><?php _e('Link Category slug') ?></label>
206 <input name="slug" id="slug" type="text" value="" size="40" />
207 <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>
210 <div class="form-field">
211 <label for="description"><?php _e('Description (optional)') ?></label>
212 <textarea name="description" id="description" rows="5" cols="40"></textarea>
213 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
216 <p class="submit"><input type="submit" class="button" name="submit" value="<?php esc_attr_e('Add Category'); ?>" /></p>
217 <?php do_action('edit_link_category_form', $category); ?>
224 </div><!-- /col-left -->
226 </div><!-- /col-container -->
229 <?php inline_edit_term_row('edit-link-categories'); ?>
230 <?php include('admin-footer.php'); ?>