1
|
1 |
<?php |
|
2 |
/** |
|
3 |
* Edit Link Categories Administration Panel. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
|
|
9 |
/** WordPress Administration Bootstrap */ |
|
10 |
require_once('admin.php'); |
|
11 |
|
|
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']; |
|
16 |
|
|
17 |
if ( !current_user_can('manage_categories') ) |
|
18 |
wp_die(__('Cheatin’ uh?')); |
|
19 |
|
|
20 |
if ( 'delete' == $doaction ) { |
|
21 |
$cats = (array) $_GET['delete']; |
|
22 |
$default_cat_id = get_option('default_link_category'); |
|
23 |
|
|
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') ) ); |
|
29 |
|
|
30 |
wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id)); |
|
31 |
} |
|
32 |
|
|
33 |
$location = 'edit-link-categories.php'; |
|
34 |
if ( $referer = wp_get_referer() ) { |
|
35 |
if ( false !== strpos($referer, 'edit-link-categories.php') ) |
|
36 |
$location = $referer; |
|
37 |
} |
|
38 |
|
|
39 |
$location = add_query_arg('message', 6, $location); |
|
40 |
wp_redirect($location); |
|
41 |
exit(); |
|
42 |
} |
|
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']) ) ); |
|
45 |
exit; |
|
46 |
} |
|
47 |
|
|
48 |
$title = __('Link Categories'); |
|
49 |
|
|
50 |
wp_enqueue_script('admin-categories'); |
|
51 |
if ( current_user_can('manage_categories') ) |
|
52 |
wp_enqueue_script('inline-edit-tax'); |
|
53 |
|
|
54 |
require_once ('admin-header.php'); |
|
55 |
|
|
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.'); ?> |
|
62 |
|
|
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']) ) ); ?> |
|
68 |
</h2> |
|
69 |
|
|
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']); |
|
73 |
endif; ?> |
|
74 |
|
|
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" /> |
|
80 |
</p> |
|
81 |
</form> |
|
82 |
<br class="clear" /> |
|
83 |
|
|
84 |
<div id="col-container"> |
|
85 |
|
|
86 |
<div id="col-right"> |
|
87 |
<div class="col-wrap"> |
|
88 |
<form id="posts-filter" action="" method="get"> |
|
89 |
<div class="tablenav"> |
|
90 |
|
|
91 |
<?php |
|
92 |
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0; |
|
93 |
if ( empty($pagenum) ) |
|
94 |
$pagenum = 1; |
|
95 |
if( ! isset( $catsperpage ) || $catsperpage < 0 ) |
|
96 |
$catsperpage = 20; |
|
97 |
|
|
98 |
$page_links = paginate_links( array( |
|
99 |
'base' => add_query_arg( 'pagenum', '%#%' ), |
|
100 |
'format' => '', |
|
101 |
'prev_text' => __('«'), |
|
102 |
'next_text' => __('»'), |
|
103 |
'total' => ceil(wp_count_terms('link_category') / $catsperpage), |
|
104 |
'current' => $pagenum |
|
105 |
)); |
|
106 |
|
|
107 |
if ( $page_links ) |
|
108 |
echo "<div class='tablenav-pages'>$page_links</div>"; |
|
109 |
?> |
|
110 |
|
|
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> |
|
115 |
</select> |
|
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'); ?> |
|
118 |
</div> |
|
119 |
|
|
120 |
<br class="clear" /> |
|
121 |
</div> |
|
122 |
|
|
123 |
<div class="clear"></div> |
|
124 |
|
|
125 |
<table class="widefat fixed" cellspacing="0"> |
|
126 |
<thead> |
|
127 |
<tr> |
|
128 |
<?php print_column_headers('edit-link-categories'); ?> |
|
129 |
</tr> |
|
130 |
</thead> |
|
131 |
|
|
132 |
<tfoot> |
|
133 |
<tr> |
|
134 |
<?php print_column_headers('edit-link-categories', false); ?> |
|
135 |
</tr> |
|
136 |
</tfoot> |
|
137 |
|
|
138 |
<tbody id="the-list" class="list:link-cat"> |
|
139 |
<?php |
|
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']; |
|
144 |
|
|
145 |
$categories = get_terms( 'link_category', $args ); |
|
146 |
if ( $categories ) { |
|
147 |
$output = ''; |
|
148 |
foreach ( $categories as $category ) { |
|
149 |
$output .= link_cat_row($category); |
|
150 |
} |
|
151 |
echo $output; |
|
152 |
unset($category); |
|
153 |
} |
|
154 |
|
|
155 |
?> |
|
156 |
</tbody> |
|
157 |
</table> |
|
158 |
|
|
159 |
<div class="tablenav"> |
|
160 |
<?php |
|
161 |
if ( $page_links ) |
|
162 |
echo "<div class='tablenav-pages'>$page_links</div>"; |
|
163 |
?> |
|
164 |
|
|
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> |
|
169 |
</select> |
|
170 |
<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> |
|
171 |
</div> |
|
172 |
|
|
173 |
<br class="clear" /> |
|
174 |
</div> |
|
175 |
<br class="clear" /> |
|
176 |
</form> |
|
177 |
|
|
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> |
|
180 |
</div> |
|
181 |
|
|
182 |
|
|
183 |
</div> |
|
184 |
</div><!-- /col-right --> |
|
185 |
|
|
186 |
<div id="col-left"> |
|
187 |
<div class="col-wrap"> |
|
188 |
|
|
189 |
<?php if ( current_user_can('manage_categories') ) { |
|
190 |
$category = (object) array(); $category->parent = 0; do_action('add_link_category_form_pre', $category); ?> |
|
191 |
|
|
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'); ?> |
|
198 |
|
|
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" /> |
|
202 |
</div> |
|
203 |
|
|
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> |
|
208 |
</div> |
|
209 |
|
|
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> |
|
214 |
</div> |
|
215 |
|
|
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); ?> |
|
218 |
</form> |
|
219 |
</div> |
|
220 |
|
|
221 |
<?php } ?> |
|
222 |
|
|
223 |
</div> |
|
224 |
</div><!-- /col-left --> |
|
225 |
|
|
226 |
</div><!-- /col-container --> |
|
227 |
</div><!-- /wrap --> |
|
228 |
|
|
229 |
<?php inline_edit_term_row('edit-link-categories'); ?> |
|
230 |
<?php include('admin-footer.php'); ?> |