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 ( ! 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 add_contextual_help($current_screen, '<p>' . __('You can create groups of links by using link categories. Link category names must be unique and link categories are separate from the categories you use for posts.') . '</p>' .
55 '<p>' . __('You can delete link categories, but that action does not delete the links within the category. Instead, it moves them to the default link category.') . '</p>' .
56 '<p><strong>' . __('For more information:') . '</strong></p>' .
57 '<p>' . __('<a href="http://codex.wordpress.org/Links_Link_Categories_SubPanel" target="_blank">Link Categories Documentation</a>') . '</p>' .
58 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
61 require_once ('admin-header.php');
63 $messages[1] = __('Category added.');
64 $messages[2] = __('Category deleted.');
65 $messages[3] = __('Category updated.');
66 $messages[4] = __('Category not added.');
67 $messages[5] = __('Category not updated.');
68 $messages[6] = __('Categories deleted.'); ?>
70 <div class="wrap nosubsub">
71 <?php screen_icon(); ?>
72 <h2><?php echo esc_html( $title );
73 if ( isset($_GET['s']) && $_GET['s'] )
74 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
77 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
78 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
79 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
82 <form class="search-form" action="" method="get">
83 <p class="search-box">
84 <label class="screen-reader-text" for="link-category-search-input"><?php _e( 'Search Categories' ); ?>:</label>
85 <input type="text" id="link-category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
86 <input type="submit" value="<?php esc_attr_e( 'Search Categories' ); ?>" class="button" />
91 <div id="col-container">
94 <div class="col-wrap">
95 <form id="posts-filter" action="" method="get">
96 <div class="tablenav">
99 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
100 if ( empty($pagenum) )
102 if ( ! isset( $catsperpage ) || $catsperpage < 0 )
105 $page_links = paginate_links( array(
106 'base' => add_query_arg( 'pagenum', '%#%' ),
108 'prev_text' => __('«'),
109 'next_text' => __('»'),
110 'total' => ceil(wp_count_terms('link_category') / $catsperpage),
111 'current' => $pagenum
115 echo "<div class='tablenav-pages'>$page_links</div>";
118 <div class="alignleft actions">
119 <select name="action">
120 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
121 <option value="delete"><?php _e('Delete'); ?></option>
123 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
124 <?php wp_nonce_field('bulk-link-categories'); ?>
130 <div class="clear"></div>
132 <table class="widefat fixed" cellspacing="0">
135 <?php print_column_headers('edit-link-categories'); ?>
141 <?php print_column_headers('edit-link-categories', false); ?>
145 <tbody id="the-list" class="list:link-cat">
147 $start = ($pagenum - 1) * $catsperpage;
148 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
149 if ( !empty( $_GET['s'] ) )
150 $args['search'] = $_GET['s'];
152 $categories = get_terms( 'link_category', $args );
155 foreach ( $categories as $category ) {
156 $output .= link_cat_row($category);
166 <div class="tablenav">
169 echo "<div class='tablenav-pages'>$page_links</div>";
172 <div class="alignleft actions">
173 <select name="action2">
174 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
175 <option value="delete"><?php _e('Delete'); ?></option>
177 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
185 <div class="form-wrap">
186 <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>
191 </div><!-- /col-right -->
194 <div class="col-wrap">
196 <?php if ( current_user_can('manage_categories') ) {
197 $category = (object) array(); $category->parent = 0; do_action('add_link_category_form_pre', $category); ?>
199 <div class="form-wrap">
200 <h3><?php _e('Add Link Category'); ?></h3>
201 <div id="ajax-response"></div>
202 <form name="addcat" id="addcat" class="add:the-list: validate" method="post" action="link-category.php">
203 <input type="hidden" name="action" value="addcat" />
204 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-link-category'); ?>
206 <div class="form-field form-required">
207 <label for="name"><?php _e('Link Category name') ?></label>
208 <input name="name" id="link-name" type="text" value="" size="40" aria-required="true" />
210 <?php if ( !global_terms_enabled() ) { ?>
211 <div class="form-field">
212 <label for="slug"><?php _e('Link Category slug') ?></label>
213 <input name="slug" id="link-slug" type="text" value="" size="40" />
214 <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>
217 <div class="form-field">
218 <label for="description"><?php _e('Description (optional)') ?></label>
219 <textarea name="description" id="link-description" rows="5" cols="40"></textarea>
220 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
223 <p class="submit"><input type="submit" class="button" name="submit" value="<?php esc_attr_e('Add Category'); ?>" /></p>
224 <?php do_action('edit_link_category_form', $category); ?>
231 </div><!-- /col-left -->
233 </div><!-- /col-container -->
236 <?php inline_edit_term_row('edit-link-categories', 'link_category'); ?>
237 <?php include('./admin-footer.php'); ?>