Make WordPress Core

Ticket #16243: edit-tags.php

File edit-tags.php, 14.9 KB (added by iamfriendly, 16 years ago)

edit-tags.php with additional error reports

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