PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/edit-tags.php

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