PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/edit-tags.php

https://bitbucket.org/crafttheweb/wordpress-fold
PHP | 420 lines | 319 code | 92 blank | 9 comment | 90 complexity | fee5ec78fe73d1acefc0b14a4e396477 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Edit Tags Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( ! $taxnow )
  11. wp_die( __( 'Invalid taxonomy' ) );
  12. $tax = get_taxonomy( $taxnow );
  13. if ( ! $tax )
  14. wp_die( __( 'Invalid taxonomy' ) );
  15. if ( ! current_user_can( $tax->cap->manage_terms ) )
  16. wp_die( __( 'Cheatin&#8217; uh?' ) );
  17. $wp_list_table = _get_list_table('WP_Terms_List_Table');
  18. $pagenum = $wp_list_table->get_pagenum();
  19. $title = $tax->labels->name;
  20. if ( 'post' != $post_type ) {
  21. $parent_file = "edit.php?post_type=$post_type";
  22. $submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type";
  23. } else if ( 'link_category' == $tax->name ) {
  24. $parent_file = 'link-manager.php';
  25. $submenu_file = 'edit-tags.php?taxonomy=link_category';
  26. } else {
  27. $parent_file = 'edit.php';
  28. $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
  29. }
  30. add_screen_option( 'per_page', array( 'label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) );
  31. switch ( $wp_list_table->current_action() ) {
  32. case 'add-tag':
  33. check_admin_referer( 'add-tag', '_wpnonce_add-tag' );
  34. if ( !current_user_can( $tax->cap->edit_terms ) )
  35. wp_die( __( 'Cheatin&#8217; uh?' ) );
  36. $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
  37. $location = 'edit-tags.php?taxonomy=' . $taxonomy;
  38. if ( 'post' != $post_type )
  39. $location .= '&post_type=' . $post_type;
  40. if ( $referer = wp_get_original_referer() ) {
  41. if ( false !== strpos( $referer, 'edit-tags.php' ) )
  42. $location = $referer;
  43. }
  44. if ( $ret && !is_wp_error( $ret ) )
  45. $location = add_query_arg( 'message', 1, $location );
  46. else
  47. $location = add_query_arg( 'message', 4, $location );
  48. wp_redirect( $location );
  49. exit;
  50. break;
  51. case 'delete':
  52. $location = 'edit-tags.php?taxonomy=' . $taxonomy;
  53. if ( 'post' != $post_type )
  54. $location .= '&post_type=' . $post_type;
  55. if ( $referer = wp_get_referer() ) {
  56. if ( false !== strpos( $referer, 'edit-tags.php' ) )
  57. $location = $referer;
  58. }
  59. if ( !isset( $_REQUEST['tag_ID'] ) ) {
  60. wp_redirect( $location );
  61. exit;
  62. }
  63. $tag_ID = (int) $_REQUEST['tag_ID'];
  64. check_admin_referer( 'delete-tag_' . $tag_ID );
  65. if ( !current_user_can( $tax->cap->delete_terms ) )
  66. wp_die( __( 'Cheatin&#8217; uh?' ) );
  67. wp_delete_term( $tag_ID, $taxonomy );
  68. $location = add_query_arg( 'message', 2, $location );
  69. wp_redirect( $location );
  70. exit;
  71. break;
  72. case 'bulk-delete':
  73. check_admin_referer( 'bulk-tags' );
  74. if ( !current_user_can( $tax->cap->delete_terms ) )
  75. wp_die( __( 'Cheatin&#8217; uh?' ) );
  76. $tags = (array) $_REQUEST['delete_tags'];
  77. foreach ( $tags as $tag_ID ) {
  78. wp_delete_term( $tag_ID, $taxonomy );
  79. }
  80. $location = 'edit-tags.php?taxonomy=' . $taxonomy;
  81. if ( 'post' != $post_type )
  82. $location .= '&post_type=' . $post_type;
  83. if ( $referer = wp_get_referer() ) {
  84. if ( false !== strpos( $referer, 'edit-tags.php' ) )
  85. $location = $referer;
  86. }
  87. $location = add_query_arg( 'message', 6, $location );
  88. wp_redirect( $location );
  89. exit;
  90. break;
  91. case 'edit':
  92. $title = $tax->labels->edit_item;
  93. $tag_ID = (int) $_REQUEST['tag_ID'];
  94. $tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' );
  95. if ( ! $tag )
  96. wp_die( __( 'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?' ) );
  97. require_once ( 'admin-header.php' );
  98. include( './edit-tag-form.php' );
  99. break;
  100. case 'editedtag':
  101. $tag_ID = (int) $_POST['tag_ID'];
  102. check_admin_referer( 'update-tag_' . $tag_ID );
  103. if ( !current_user_can( $tax->cap->edit_terms ) )
  104. wp_die( __( 'Cheatin&#8217; uh?' ) );
  105. $tag = get_term( $tag_ID, $taxonomy );
  106. if ( ! $tag )
  107. wp_die( __( 'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?' ) );
  108. $ret = wp_update_term( $tag_ID, $taxonomy, $_POST );
  109. $location = 'edit-tags.php?taxonomy=' . $taxonomy;
  110. if ( 'post' != $post_type )
  111. $location .= '&post_type=' . $post_type;
  112. if ( $referer = wp_get_original_referer() ) {
  113. if ( false !== strpos( $referer, 'edit-tags.php' ) )
  114. $location = $referer;
  115. }
  116. if ( $ret && !is_wp_error( $ret ) )
  117. $location = add_query_arg( 'message', 3, $location );
  118. else
  119. $location = add_query_arg( 'message', 5, $location );
  120. wp_redirect( $location );
  121. exit;
  122. break;
  123. default:
  124. if ( ! empty($_REQUEST['_wp_http_referer']) ) {
  125. $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) );
  126. if ( ! empty( $_REQUEST['paged'] ) )
  127. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'] );
  128. wp_redirect( $location );
  129. exit;
  130. }
  131. $wp_list_table->prepare_items();
  132. $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
  133. if ( $pagenum > $total_pages && $total_pages > 0 ) {
  134. wp_redirect( add_query_arg( 'paged', $total_pages ) );
  135. exit;
  136. }
  137. wp_enqueue_script('admin-tags');
  138. if ( current_user_can($tax->cap->edit_terms) )
  139. wp_enqueue_script('inline-edit-tax');
  140. if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) {
  141. $help ='';
  142. if ( 'category' == $taxonomy )
  143. $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>';
  144. elseif ( 'link_category' == $taxonomy )
  145. $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>';
  146. else
  147. $help = '<p>' . __( 'You can assign keywords to your posts using <strong>tags</strong>. Unlike categories, tags have no hierarchy, meaning there&#8217;s no relationship from one tag to another.' ) . '</p>';
  148. if ( 'link_category' == $taxonomy )
  149. $help .= '<p>' . __( 'You can delete Link Categories in the Bulk Action pull-down, but that action does not delete the links within the category. Instead, it moves them to the default Link Category.' ) . '</p>';
  150. else
  151. $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>';
  152. get_current_screen()->add_help_tab( array(
  153. 'id' => 'overview',
  154. 'title' => __('Overview'),
  155. 'content' => $help,
  156. ) );
  157. if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) {
  158. if ( 'category' == $taxonomy )
  159. $help = '<p>' . __( 'When adding a new category on this screen, you&#8217;ll fill in the following fields:' ) . '</p>';
  160. else
  161. $help = '<p>' . __( 'When adding a new tag on this screen, you&#8217;ll fill in the following fields:' ) . '</p>';
  162. $help .= '<ul>' .
  163. '<li>' . __( '<strong>Name</strong> - The name is how it appears on your site.' ) . '</li>';
  164. if ( ! global_terms_enabled() )
  165. $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>';
  166. if ( 'category' == $taxonomy )
  167. $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>';
  168. $help .= '<li>' . __( '<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.' ) . '</li>' .
  169. '</ul>' .
  170. '<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>';
  171. get_current_screen()->add_help_tab( array(
  172. 'id' => 'adding-terms',
  173. 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ),
  174. 'content' => $help,
  175. ) );
  176. }
  177. $help = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
  178. if ( 'category' == $taxonomy )
  179. $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Categories_Screen" target="_blank">Documentation on Categories</a>' ) . '</p>';
  180. elseif ( 'link_category' == $taxonomy )
  181. $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Links_Link_Categories_Screen" target="_blank">Documentation on Link Categories</a>' ) . '</p>';
  182. else
  183. $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Tags_Screen" target="_blank">Documentation on Tags</a>' ) . '</p>';
  184. $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
  185. get_current_screen()->set_help_sidebar( $help );
  186. unset( $help );
  187. }
  188. require_once ('admin-header.php');
  189. if ( !current_user_can($tax->cap->edit_terms) )
  190. wp_die( __('You are not allowed to edit this item.') );
  191. $messages[1] = __('Item added.');
  192. $messages[2] = __('Item deleted.');
  193. $messages[3] = __('Item updated.');
  194. $messages[4] = __('Item not added.');
  195. $messages[5] = __('Item not updated.');
  196. $messages[6] = __('Items deleted.');
  197. ?>
  198. <div class="wrap nosubsub">
  199. <?php screen_icon(); ?>
  200. <h2><?php echo esc_html( $title );
  201. if ( !empty($_REQUEST['s']) )
  202. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
  203. </h2>
  204. <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
  205. <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
  206. <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
  207. endif; ?>
  208. <div id="ajax-response"></div>
  209. <form class="search-form" action="" method="get">
  210. <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
  211. <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
  212. <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
  213. </form>
  214. <br class="clear" />
  215. <div id="col-container">
  216. <div id="col-right">
  217. <div class="col-wrap">
  218. <form id="posts-filter" action="" method="post">
  219. <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
  220. <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
  221. <?php $wp_list_table->display(); ?>
  222. <br class="clear" />
  223. </form>
  224. <?php if ( 'category' == $taxonomy ) : ?>
  225. <div class="form-wrap">
  226. <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>
  227. <?php if ( current_user_can( 'import' ) ) : ?>
  228. <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
  229. <?php endif; ?>
  230. </div>
  231. <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
  232. <div class="form-wrap">
  233. <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>.'), 'import.php') ;?></p>
  234. </div>
  235. <?php endif;
  236. do_action('after-' . $taxonomy . '-table', $taxonomy);
  237. ?>
  238. </div>
  239. </div><!-- /col-right -->
  240. <div id="col-left">
  241. <div class="col-wrap">
  242. <?php
  243. if ( !is_null( $tax->labels->popular_items ) ) {
  244. if ( current_user_can( $tax->cap->edit_terms ) )
  245. $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
  246. else
  247. $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
  248. if ( $tag_cloud ) :
  249. ?>
  250. <div class="tagcloud">
  251. <h3><?php echo $tax->labels->popular_items; ?></h3>
  252. <?php echo $tag_cloud; unset( $tag_cloud ); ?>
  253. </div>
  254. <?php
  255. endif;
  256. }
  257. if ( current_user_can($tax->cap->edit_terms) ) {
  258. // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
  259. if ( 'category' == $taxonomy )
  260. do_action('add_category_form_pre', (object)array('parent' => 0) );
  261. elseif ( 'link_category' == $taxonomy )
  262. do_action('add_link_category_form_pre', (object)array('parent' => 0) );
  263. else
  264. do_action('add_tag_form_pre', $taxonomy);
  265. do_action($taxonomy . '_pre_add_form', $taxonomy);
  266. ?>
  267. <div class="form-wrap">
  268. <h3><?php echo $tax->labels->add_new_item; ?></h3>
  269. <form id="addtag" method="post" action="edit-tags.php" class="validate">
  270. <input type="hidden" name="action" value="add-tag" />
  271. <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
  272. <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
  273. <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
  274. <?php wp_nonce_field('add-tag', '_wpnonce_add-tag'); ?>
  275. <div class="form-field form-required">
  276. <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
  277. <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
  278. <p><?php _e('The name is how it appears on your site.'); ?></p>
  279. </div>
  280. <?php if ( ! global_terms_enabled() ) : ?>
  281. <div class="form-field">
  282. <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
  283. <input name="slug" id="tag-slug" type="text" value="" size="40" />
  284. <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>
  285. </div>
  286. <?php endif; // global_terms_enabled() ?>
  287. <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
  288. <div class="form-field">
  289. <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
  290. <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
  291. <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
  292. <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>
  293. <?php endif; ?>
  294. </div>
  295. <?php endif; // is_taxonomy_hierarchical() ?>
  296. <div class="form-field">
  297. <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
  298. <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
  299. <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
  300. </div>
  301. <?php
  302. if ( ! is_taxonomy_hierarchical($taxonomy) )
  303. do_action('add_tag_form_fields', $taxonomy);
  304. do_action($taxonomy . '_add_form_fields', $taxonomy);
  305. submit_button( $tax->labels->add_new_item );
  306. // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
  307. if ( 'category' == $taxonomy )
  308. do_action('edit_category_form', (object)array('parent' => 0) );
  309. elseif ( 'link_category' == $taxonomy )
  310. do_action('edit_link_category_form', (object)array('parent' => 0) );
  311. else
  312. do_action('add_tag_form', $taxonomy);
  313. do_action($taxonomy . '_add_form', $taxonomy);
  314. ?>
  315. </form></div>
  316. <?php } ?>
  317. </div>
  318. </div><!-- /col-left -->
  319. </div><!-- /col-container -->
  320. </div><!-- /wrap -->
  321. <script type="text/javascript">
  322. try{document.forms.addtag['tag-name'].focus();}catch(e){}
  323. </script>
  324. <?php $wp_list_table->inline_edit(); ?>
  325. <?php
  326. break;
  327. }
  328. include('./admin-footer.php');