1 | <?php |
---|
2 | /** |
---|
3 | * Edit Tags Administration Panel. |
---|
4 | * |
---|
5 | * @package WordPress |
---|
6 | * @subpackage Administration |
---|
7 | */ |
---|
8 | |
---|
9 | /** WordPress Administration Bootstrap */ |
---|
10 | require_once('./admin.php'); |
---|
11 | $tax = get_taxonomy( $taxnow ); |
---|
12 | if ( !current_user_can( $tax->cap->manage_terms ) ) |
---|
13 | wp_die( __( 'Cheatin’ uh?' ) ); |
---|
14 | |
---|
15 | $wp_list_table = get_list_table('WP_Terms_List_Table'); |
---|
16 | $wp_list_table->check_permissions(); |
---|
17 | |
---|
18 | $title = $tax->labels->name; |
---|
19 | |
---|
20 | if ( 'post' != $post_type ) { |
---|
21 | $parent_file = "edit.php?post_type=$post_type"; |
---|
22 | $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type"; |
---|
23 | } else { |
---|
24 | $parent_file = 'edit.php'; |
---|
25 | $submenu_file = "edit-tags.php?taxonomy=$taxonomy"; |
---|
26 | } |
---|
27 | |
---|
28 | add_screen_option( 'per_page', array('label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page') ); |
---|
29 | |
---|
30 | switch ( $wp_list_table->current_action() ) { |
---|
31 | |
---|
32 | case 'add-tag': |
---|
33 | |
---|
34 | check_admin_referer( 'add-tag' ); |
---|
35 | |
---|
36 | if ( !current_user_can( $tax->cap->edit_terms ) ) |
---|
37 | wp_die( __( 'Cheatin’ uh?' ) ); |
---|
38 | |
---|
39 | $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); |
---|
40 | $location = 'edit-tags.php?taxonomy=' . $taxonomy; |
---|
41 | if ( 'post' != $post_type ) |
---|
42 | $location .= '&post_type=' . $post_type; |
---|
43 | |
---|
44 | if ( $referer = wp_get_original_referer() ) { |
---|
45 | if ( false !== strpos( $referer, 'edit-tags.php' ) ) |
---|
46 | $location = $referer; |
---|
47 | } |
---|
48 | |
---|
49 | if ( $ret && !is_wp_error( $ret ) ) |
---|
50 | $location = add_query_arg( 'message', 1, $location ); |
---|
51 | else |
---|
52 | $location = add_query_arg( 'message', 4, $location ); |
---|
53 | wp_redirect( $location ); |
---|
54 | exit; |
---|
55 | break; |
---|
56 | |
---|
57 | case 'delete': |
---|
58 | $location = 'edit-tags.php?taxonomy=' . $taxonomy; |
---|
59 | if ( 'post' != $post_type ) |
---|
60 | $location .= '&post_type=' . $post_type; |
---|
61 | if ( $referer = wp_get_referer() ) { |
---|
62 | if ( false !== strpos( $referer, 'edit-tags.php' ) ) |
---|
63 | $location = $referer; |
---|
64 | } |
---|
65 | |
---|
66 | if ( !isset( $_REQUEST['tag_ID'] ) ) { |
---|
67 | wp_redirect( $location ); |
---|
68 | exit; |
---|
69 | } |
---|
70 | |
---|
71 | $tag_ID = (int) $_REQUEST['tag_ID']; |
---|
72 | check_admin_referer( 'delete-tag_' . $tag_ID ); |
---|
73 | |
---|
74 | if ( !current_user_can( $tax->cap->delete_terms ) ) |
---|
75 | wp_die( __( 'Cheatin’ uh?' ) ); |
---|
76 | |
---|
77 | wp_delete_term( $tag_ID, $taxonomy ); |
---|
78 | |
---|
79 | $location = add_query_arg( 'message', 2, $location ); |
---|
80 | wp_redirect( $location ); |
---|
81 | exit; |
---|
82 | |
---|
83 | break; |
---|
84 | |
---|
85 | case 'bulk-delete': |
---|
86 | check_admin_referer( 'bulk-tags' ); |
---|
87 | |
---|
88 | if ( !current_user_can( $tax->cap->delete_terms ) ) |
---|
89 | wp_die( __( 'Cheatin’ uh?' ) ); |
---|
90 | |
---|
91 | $tags = (array) $_REQUEST['delete_tags']; |
---|
92 | foreach ( $tags as $tag_ID ) { |
---|
93 | wp_delete_term( $tag_ID, $taxonomy ); |
---|
94 | } |
---|
95 | |
---|
96 | $location = 'edit-tags.php?taxonomy=' . $taxonomy; |
---|
97 | if ( 'post' != $post_type ) |
---|
98 | $location .= '&post_type=' . $post_type; |
---|
99 | if ( $referer = wp_get_referer() ) { |
---|
100 | if ( false !== strpos( $referer, 'edit-tags.php' ) ) |
---|
101 | $location = $referer; |
---|
102 | } |
---|
103 | |
---|
104 | $location = add_query_arg( 'message', 6, $location ); |
---|
105 | wp_redirect( $location ); |
---|
106 | exit; |
---|
107 | |
---|
108 | break; |
---|
109 | |
---|
110 | case 'edit': |
---|
111 | $title = $tax->labels->edit_item; |
---|
112 | |
---|
113 | require_once ( 'admin-header.php' ); |
---|
114 | $tag_ID = (int) $_REQUEST['tag_ID']; |
---|
115 | |
---|
116 | $tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' ); |
---|
117 | include( './edit-tag-form.php' ); |
---|
118 | |
---|
119 | break; |
---|
120 | |
---|
121 | case 'editedtag': |
---|
122 | $tag_ID = (int) $_POST['tag_ID']; |
---|
123 | check_admin_referer( 'update-tag_' . $tag_ID ); |
---|
124 | |
---|
125 | if ( !current_user_can( $tax->cap->edit_terms ) ) |
---|
126 | wp_die( __( 'Cheatin’ uh?' ) ); |
---|
127 | |
---|
128 | $ret = wp_update_term( $tag_ID, $taxonomy, $_POST ); |
---|
129 | |
---|
130 | $location = 'edit-tags.php?taxonomy=' . $taxonomy; |
---|
131 | if ( 'post' != $post_type ) |
---|
132 | $location .= '&post_type=' . $post_type; |
---|
133 | |
---|
134 | if ( $referer = wp_get_original_referer() ) { |
---|
135 | if ( false !== strpos( $referer, 'edit-tags.php' ) ) |
---|
136 | $location = $referer; |
---|
137 | } |
---|
138 | |
---|
139 | if ( $ret && !is_wp_error( $ret ) ) |
---|
140 | $location = add_query_arg( 'message', 3, $location ); |
---|
141 | else |
---|
142 | $location = add_query_arg( 'message', 5, $location ); |
---|
143 | |
---|
144 | wp_redirect( $location ); |
---|
145 | exit; |
---|
146 | break; |
---|
147 | |
---|
148 | default: |
---|
149 | |
---|
150 | if ( ! empty($_REQUEST['_wp_http_referer']) ) { |
---|
151 | wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); |
---|
152 | exit; |
---|
153 | } |
---|
154 | |
---|
155 | $wp_list_table->prepare_items(); |
---|
156 | |
---|
157 | wp_enqueue_script('admin-tags'); |
---|
158 | if ( current_user_can($tax->cap->edit_terms) ) |
---|
159 | wp_enqueue_script('inline-edit-tax'); |
---|
160 | |
---|
161 | if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) { |
---|
162 | if ( 'category' == $taxonomy ) |
---|
163 | $help = '<p>' . sprintf(__('You can use categories to define sections of your site and group related posts. The default category is “Uncategorized” until you change it in your <a href="%s">writing settings</a>.'), 'options-writing.php') . '</p>'; |
---|
164 | elseif ( 'link_category' == $taxonomy ) |
---|
165 | $help = '<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>'; |
---|
166 | else |
---|
167 | $help = '<p>' . __('You can assign keywords to your posts using Post Tags. Unlike categories, tags have no hierarchy, meaning there’s no relationship from one tag to another.') . '</p>'; |
---|
168 | |
---|
169 | if ( 'category' == $taxonomy ) |
---|
170 | $help .='<p>' . __('What’s the difference between categories and tags? Normally, tags are ad-hoc keywords that identify important information in your post (names, subjects, etc) that may or may not recur in other posts, while categories are pre-determined sections. If you think of your site like a book, the categories are like the Table of Contents and the tags are like the terms in the index.') . '</p>'; |
---|
171 | elseif ( 'link_category' == $taxonomy ) |
---|
172 | $help = '<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. You can delete link categories in the Bulk Action pulldown, but that action does not delete the links within the category. Instead, it moves them to the default link category.') . '</p>'; |
---|
173 | else |
---|
174 | $help .='<p>' . __('What’s the difference between categories and tags? Normally, tags are ad-hoc keywords that identify important information in your post (names, subjects, etc) that may or may not recur in other posts, while categories are pre-determined sections. If you think of your site like a book, the categories are like the Table of Contents and the tags are like the terms in the index.') . '</p>'; |
---|
175 | |
---|
176 | if ( 'category' == $taxonomy ) |
---|
177 | $help .= '<p>' . __('When adding a new category on this screen, you’ll fill in the following fields:') . '</p>'; |
---|
178 | elseif ( 'post_tag' == $taxonomy ) |
---|
179 | $help .= '<p>' . __('When adding a new tag on this screen, you’ll fill in the following fields:') . '</p>'; |
---|
180 | |
---|
181 | if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) |
---|
182 | |
---|
183 | $help .= '<ul>' . |
---|
184 | '<li>' . __('<strong>Name</strong> - The name is how it appears on your site.') . '</li>'; |
---|
185 | |
---|
186 | if ( ! global_terms_enabled() ) |
---|
187 | if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) |
---|
188 | $help .= '<li>' . __('<strong>Slug</strong> - The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.') . '</li>'; |
---|
189 | |
---|
190 | if ( 'category' == $taxonomy ) |
---|
191 | $help .= '<li>' . __('<strong>Parent</strong> - Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional. To create a subcategory, just choose another category from the Parent dropdown.') . '</li>'; |
---|
192 | |
---|
193 | if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) |
---|
194 | $help .= '<li>' . __('<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.') . '</li>' . |
---|
195 | '</ul>' . |
---|
196 | '<p>' . __('You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen and to display/hide columns in the table.') . '</p>' . |
---|
197 | '<p><strong>' . __('For more information:') . '</strong></p>'; |
---|
198 | |
---|
199 | if ( 'category' == $taxonomy ) |
---|
200 | $help .= '<p>' . __('<a href="http://codex.wordpress.org/Manage_Categories_SubPanel" target="_blank">Documentation on Categories </a>') . '</p>'; |
---|
201 | elseif ( 'link_category' == $taxonomy ) |
---|
202 | $help .= '<p>' . __('<a href="http://codex.wordpress.org/Links_Link_Categories_SubPanel" target="_blank">Documentation on Link Categories </a>') . '</p>'; |
---|
203 | else |
---|
204 | $help .= '<p>' . __('<a href="http://codex.wordpress.org/Post_Tags_SubPanel" target="_blank">Documentation on Post Tags </a>') . '</p>'; |
---|
205 | |
---|
206 | $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'; |
---|
207 | |
---|
208 | add_contextual_help($current_screen, $help); |
---|
209 | unset($help); |
---|
210 | } |
---|
211 | |
---|
212 | require_once ('admin-header.php'); |
---|
213 | |
---|
214 | if ( !current_user_can($tax->cap->edit_terms) ) |
---|
215 | wp_die( __('You are not allowed to edit this item.') ); |
---|
216 | |
---|
217 | $messages[1] = __('Item added.'); |
---|
218 | $messages[2] = __('Item deleted.'); |
---|
219 | $messages[3] = __('Item updated.'); |
---|
220 | $messages[4] = __('Item not added.'); |
---|
221 | $messages[5] = __('Item not updated.'); |
---|
222 | $messages[6] = __('Items deleted.'); |
---|
223 | |
---|
224 | ?> |
---|
225 | |
---|
226 | <div class="wrap nosubsub"> |
---|
227 | <?php screen_icon(); ?> |
---|
228 | <h2><?php echo esc_html( $title ); |
---|
229 | if ( !empty($_REQUEST['s']) ) |
---|
230 | printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?> |
---|
231 | </h2> |
---|
232 | |
---|
233 | <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?> |
---|
234 | <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div> |
---|
235 | <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); |
---|
236 | endif; ?> |
---|
237 | <div id="ajax-response"></div> |
---|
238 | |
---|
239 | <form class="search-form" action="" method="get"> |
---|
240 | <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" /> |
---|
241 | <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" /> |
---|
242 | <p class="search-box"> |
---|
243 | <label class="screen-reader-text" for="tag-search-input"><?php echo $tax->labels->search_items; ?>:</label> |
---|
244 | <input type="text" id="tag-search-input" name="s" value="<?php _admin_search_query(); ?>" /> |
---|
245 | <?php submit_button( $tax->labels->search_items, 'button', 'submit', false ); ?> |
---|
246 | </p> |
---|
247 | </form> |
---|
248 | <br class="clear" /> |
---|
249 | |
---|
250 | <div id="col-container"> |
---|
251 | |
---|
252 | <div id="col-right"> |
---|
253 | <div class="col-wrap"> |
---|
254 | <form id="posts-filter" action="" method="post"> |
---|
255 | <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" /> |
---|
256 | <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" /> |
---|
257 | |
---|
258 | <?php $wp_list_table->display_table(); ?> |
---|
259 | |
---|
260 | <br class="clear" /> |
---|
261 | </form> |
---|
262 | |
---|
263 | <?php if ( 'category' == $taxonomy ) : ?> |
---|
264 | <div class="form-wrap"> |
---|
265 | <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?></p> |
---|
266 | <?php if ( current_user_can( 'import' ) ) : ?> |
---|
267 | <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p> |
---|
268 | <?php endif; ?> |
---|
269 | </div> |
---|
270 | <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?> |
---|
271 | <div class="form-wrap"> |
---|
272 | <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p> |
---|
273 | </div> |
---|
274 | <?php endif; |
---|
275 | do_action('after-' . $taxonomy . '-table', $taxonomy); |
---|
276 | ?> |
---|
277 | |
---|
278 | </div> |
---|
279 | </div><!-- /col-right --> |
---|
280 | |
---|
281 | <div id="col-left"> |
---|
282 | <div class="col-wrap"> |
---|
283 | |
---|
284 | <?php |
---|
285 | |
---|
286 | if ( !is_null( $tax->labels->popular_items ) ) { |
---|
287 | if ( current_user_can( $tax->cap->edit_terms ) ) |
---|
288 | $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) ); |
---|
289 | else |
---|
290 | $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) ); |
---|
291 | |
---|
292 | if ( $tag_cloud ) : |
---|
293 | ?> |
---|
294 | <div class="tagcloud"> |
---|
295 | <h3><?php echo $tax->labels->popular_items; ?></h3> |
---|
296 | <?php echo $tag_cloud; unset( $tag_cloud ); ?> |
---|
297 | </div> |
---|
298 | <?php |
---|
299 | endif; |
---|
300 | } |
---|
301 | |
---|
302 | if ( current_user_can($tax->cap->edit_terms) ) { |
---|
303 | // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form |
---|
304 | if ( 'category' == $taxonomy ) |
---|
305 | do_action('add_category_form_pre', (object)array('parent' => 0) ); |
---|
306 | elseif ( 'link_category' == $taxonomy ) |
---|
307 | do_action('add_link_category_form_pre', (object)array('parent' => 0) ); |
---|
308 | else |
---|
309 | do_action('add_tag_form_pre', $taxonomy); |
---|
310 | |
---|
311 | do_action($taxonomy . '_pre_add_form', $taxonomy); |
---|
312 | ?> |
---|
313 | |
---|
314 | <div class="form-wrap"> |
---|
315 | <h3><?php echo $tax->labels->add_new_item; ?></h3> |
---|
316 | <form id="addtag" method="post" action="edit-tags.php" class="validate"> |
---|
317 | <input type="hidden" name="action" value="add-tag" /> |
---|
318 | <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" /> |
---|
319 | <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" /> |
---|
320 | <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" /> |
---|
321 | <?php wp_nonce_field('add-tag'); ?> |
---|
322 | |
---|
323 | <div class="form-field form-required"> |
---|
324 | <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label> |
---|
325 | <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" /> |
---|
326 | <p><?php _e('The name is how it appears on your site.'); ?></p> |
---|
327 | </div> |
---|
328 | <?php if ( ! global_terms_enabled() ) : ?> |
---|
329 | <div class="form-field"> |
---|
330 | <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label> |
---|
331 | <input name="slug" id="tag-slug" type="text" value="" size="40" /> |
---|
332 | <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> |
---|
333 | </div> |
---|
334 | <?php endif; // global_terms_enabled() ?> |
---|
335 | <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?> |
---|
336 | <div class="form-field"> |
---|
337 | <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label> |
---|
338 | <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?> |
---|
339 | <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?> |
---|
340 | <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p> |
---|
341 | <?php endif; ?> |
---|
342 | </div> |
---|
343 | <?php endif; // is_taxonomy_hierarchical() ?> |
---|
344 | <div class="form-field"> |
---|
345 | <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label> |
---|
346 | <textarea name="description" id="tag-description" rows="5" cols="40"></textarea> |
---|
347 | <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p> |
---|
348 | </div> |
---|
349 | |
---|
350 | <?php |
---|
351 | if ( ! is_taxonomy_hierarchical($taxonomy) ) |
---|
352 | do_action('add_tag_form_fields', $taxonomy); |
---|
353 | do_action($taxonomy . '_add_form_fields', $taxonomy); |
---|
354 | |
---|
355 | submit_button( $tax->labels->add_new_item ); |
---|
356 | |
---|
357 | // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form |
---|
358 | if ( 'category' == $taxonomy ) |
---|
359 | do_action('edit_category_form', (object)array('parent' => 0) ); |
---|
360 | elseif ( 'link_category' == $taxonomy ) |
---|
361 | do_action('edit_link_category_form', (object)array('parent' => 0) ); |
---|
362 | else |
---|
363 | do_action('add_tag_form', $taxonomy); |
---|
364 | |
---|
365 | do_action($taxonomy . '_add_form', $taxonomy); |
---|
366 | ?> |
---|
367 | </form></div> |
---|
368 | <?php } ?> |
---|
369 | |
---|
370 | </div> |
---|
371 | </div><!-- /col-left --> |
---|
372 | |
---|
373 | </div><!-- /col-container --> |
---|
374 | </div><!-- /wrap --> |
---|
375 | |
---|
376 | <?php $wp_list_table->inline_edit(); ?> |
---|
377 | |
---|
378 | <?php |
---|
379 | break; |
---|
380 | } |
---|
381 | |
---|
382 | include('./admin-footer.php'); |
---|
383 | |
---|
384 | ?> |
---|