edit-tag-form.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /**
  3. * Edit tag form for inclusion in administration panels.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. // don't load directly
  9. if ( ! defined( 'ABSPATH' ) ) {
  10. die( '-1' );
  11. }
  12. // Back compat hooks
  13. if ( 'category' == $taxonomy ) {
  14. /**
  15. * Fires before the Edit Category form.
  16. *
  17. * @since 2.1.0
  18. * @deprecated 3.0.0 Use {$taxonomy}_pre_edit_form instead.
  19. *
  20. * @param object $tag Current category term object.
  21. */
  22. do_action( 'edit_category_form_pre', $tag );
  23. } elseif ( 'link_category' == $taxonomy ) {
  24. /**
  25. * Fires before the Edit Link Category form.
  26. *
  27. * @since 2.3.0
  28. * @deprecated 3.0.0 Use {$taxonomy}_pre_edit_form instead.
  29. *
  30. * @param object $tag Current link category term object.
  31. */
  32. do_action( 'edit_link_category_form_pre', $tag );
  33. } else {
  34. /**
  35. * Fires before the Edit Tag form.
  36. *
  37. * @since 2.5.0
  38. * @deprecated 3.0.0 Use {$taxonomy}_pre_edit_form instead.
  39. *
  40. * @param object $tag Current tag term object.
  41. */
  42. do_action( 'edit_tag_form_pre', $tag );
  43. }
  44. /**
  45. * Use with caution, see https://codex.wordpress.org/Function_Reference/wp_reset_vars
  46. */
  47. wp_reset_vars( array( 'wp_http_referer' ) );
  48. $wp_http_referer = remove_query_arg( array( 'action', 'message', 'tag_ID' ), $wp_http_referer );
  49. /** Also used by Edit Tags */
  50. require_once( ABSPATH . 'wp-admin/includes/edit-tag-messages.php' );
  51. /**
  52. * Fires before the Edit Term form for all taxonomies.
  53. *
  54. * The dynamic portion of the hook name, `$taxonomy`, refers to
  55. * the taxonomy slug.
  56. *
  57. * @since 3.0.0
  58. *
  59. * @param object $tag Current taxonomy term object.
  60. * @param string $taxonomy Current $taxonomy slug.
  61. */
  62. do_action( "{$taxonomy}_pre_edit_form", $tag, $taxonomy ); ?>
  63. <div class="wrap">
  64. <h1><?php echo $tax->labels->edit_item; ?></h1>
  65. <?php if ( $message ) : ?>
  66. <div id="message" class="updated">
  67. <p><strong><?php echo $message; ?></strong></p>
  68. <?php if ( $wp_http_referer ) { ?>
  69. <p><a href="<?php echo esc_url( wp_validate_redirect( esc_url_raw( $wp_http_referer ), admin_url( 'term.php?taxonomy=' . $taxonomy ) ) ); ?>"><?php
  70. echo esc_html( $tax->labels->back_to_items );
  71. ?></a></p>
  72. <?php } ?>
  73. </div>
  74. <?php endif; ?>
  75. <div id="ajax-response"></div>
  76. <form name="edittag" id="edittag" method="post" action="edit-tags.php" class="validate"<?php
  77. /**
  78. * Fires inside the Edit Term form tag.
  79. *
  80. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
  81. *
  82. * @since 3.7.0
  83. */
  84. do_action( "{$taxonomy}_term_edit_form_tag" );
  85. ?>>
  86. <input type="hidden" name="action" value="editedtag"/>
  87. <input type="hidden" name="tag_ID" value="<?php echo esc_attr( $tag_ID ) ?>"/>
  88. <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ) ?>"/>
  89. <?php
  90. wp_original_referer_field( true, 'previous' );
  91. wp_nonce_field( 'update-tag_' . $tag_ID );
  92. /**
  93. * Fires at the beginning of the Edit Term form.
  94. *
  95. * At this point, the required hidden fields and nonces have already been output.
  96. *
  97. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
  98. *
  99. * @since 4.5.0
  100. *
  101. * @param object $tag Current taxonomy term object.
  102. * @param string $taxonomy Current $taxonomy slug.
  103. */
  104. do_action( "{$taxonomy}_term_edit_form_top", $tag, $taxonomy );
  105. ?>
  106. <table class="form-table">
  107. <tr class="form-field form-required term-name-wrap">
  108. <th scope="row"><label for="name"><?php _ex( 'Name', 'term name' ); ?></label></th>
  109. <td><input name="name" id="name" type="text" value="<?php if ( isset( $tag->name ) ) echo esc_attr($tag->name); ?>" size="40" aria-required="true" />
  110. <p class="description"><?php _e('The name is how it appears on your site.'); ?></p></td>
  111. </tr>
  112. <?php if ( !global_terms_enabled() ) { ?>
  113. <tr class="form-field term-slug-wrap">
  114. <th scope="row"><label for="slug"><?php _e( 'Slug' ); ?></label></th>
  115. <?php
  116. /**
  117. * Filters the editable slug.
  118. *
  119. * Note: This is a multi-use hook in that it is leveraged both for editable
  120. * post URIs and term slugs.
  121. *
  122. * @since 2.6.0
  123. * @since 4.4.0 The `$tag` parameter was added.
  124. *
  125. * @param string $slug The editable slug. Will be either a term slug or post URI depending
  126. * upon the context in which it is evaluated.
  127. * @param object|WP_Post $tag Term or WP_Post object.
  128. */
  129. $slug = isset( $tag->slug ) ? apply_filters( 'editable_slug', $tag->slug, $tag ) : '';
  130. ?>
  131. <td><input name="slug" id="slug" type="text" value="<?php echo esc_attr( $slug ); ?>" size="40" />
  132. <p class="description"><?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></td>
  133. </tr>
  134. <?php } ?>
  135. <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
  136. <tr class="form-field term-parent-wrap">
  137. <th scope="row"><label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label></th>
  138. <td>
  139. <?php
  140. $dropdown_args = array(
  141. 'hide_empty' => 0,
  142. 'hide_if_empty' => false,
  143. 'taxonomy' => $taxonomy,
  144. 'name' => 'parent',
  145. 'orderby' => 'name',
  146. 'selected' => $tag->parent,
  147. 'exclude_tree' => $tag->term_id,
  148. 'hierarchical' => true,
  149. 'show_option_none' => __( 'None' ),
  150. );
  151. /** This filter is documented in wp-admin/edit-tags.php */
  152. $dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'edit' );
  153. wp_dropdown_categories( $dropdown_args ); ?>
  154. <?php if ( 'category' == $taxonomy ) : ?>
  155. <p class="description"><?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>
  156. <?php else : ?>
  157. <p class="description"><?php _e( 'Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.' ); ?></p>
  158. <?php endif; ?>
  159. </td>
  160. </tr>
  161. <?php endif; // is_taxonomy_hierarchical() ?>
  162. <tr class="form-field term-description-wrap">
  163. <th scope="row"><label for="description"><?php _e( 'Description' ); ?></label></th>
  164. <td><textarea name="description" id="description" rows="5" cols="50" class="large-text"><?php echo $tag->description; // textarea_escaped ?></textarea>
  165. <p class="description"><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p></td>
  166. </tr>
  167. <?php
  168. // Back compat hooks
  169. if ( 'category' == $taxonomy ) {
  170. /**
  171. * Fires after the Edit Category form fields are displayed.
  172. *
  173. * @since 2.9.0
  174. * @deprecated 3.0.0 Use {$taxonomy}_edit_form_fields instead.
  175. *
  176. * @param object $tag Current category term object.
  177. */
  178. do_action( 'edit_category_form_fields', $tag );
  179. } elseif ( 'link_category' == $taxonomy ) {
  180. /**
  181. * Fires after the Edit Link Category form fields are displayed.
  182. *
  183. * @since 2.9.0
  184. * @deprecated 3.0.0 Use {$taxonomy}_edit_form_fields instead.
  185. *
  186. * @param object $tag Current link category term object.
  187. */
  188. do_action( 'edit_link_category_form_fields', $tag );
  189. } else {
  190. /**
  191. * Fires after the Edit Tag form fields are displayed.
  192. *
  193. * @since 2.9.0
  194. * @deprecated 3.0.0 Use {$taxonomy}_edit_form_fields instead.
  195. *
  196. * @param object $tag Current tag term object.
  197. */
  198. do_action( 'edit_tag_form_fields', $tag );
  199. }
  200. /**
  201. * Fires after the Edit Term form fields are displayed.
  202. *
  203. * The dynamic portion of the hook name, `$taxonomy`, refers to
  204. * the taxonomy slug.
  205. *
  206. * @since 3.0.0
  207. *
  208. * @param object $tag Current taxonomy term object.
  209. * @param string $taxonomy Current taxonomy slug.
  210. */
  211. do_action( "{$taxonomy}_edit_form_fields", $tag, $taxonomy );
  212. ?>
  213. </table>
  214. <?php
  215. // Back compat hooks
  216. if ( 'category' == $taxonomy ) {
  217. /** This action is documented in wp-admin/edit-tags.php */
  218. do_action( 'edit_category_form', $tag );
  219. } elseif ( 'link_category' == $taxonomy ) {
  220. /** This action is documented in wp-admin/edit-tags.php */
  221. do_action( 'edit_link_category_form', $tag );
  222. } else {
  223. /**
  224. * Fires at the end of the Edit Term form.
  225. *
  226. * @since 2.5.0
  227. * @deprecated 3.0.0 Use {$taxonomy}_edit_form instead.
  228. *
  229. * @param object $tag Current taxonomy term object.
  230. */
  231. do_action( 'edit_tag_form', $tag );
  232. }
  233. /**
  234. * Fires at the end of the Edit Term form for all taxonomies.
  235. *
  236. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
  237. *
  238. * @since 3.0.0
  239. *
  240. * @param object $tag Current taxonomy term object.
  241. * @param string $taxonomy Current taxonomy slug.
  242. */
  243. do_action( "{$taxonomy}_edit_form", $tag, $taxonomy );
  244. ?>
  245. <div class="edit-tag-actions">
  246. <?php submit_button( __( 'Update' ), 'primary', null, false ); ?>
  247. <?php if ( current_user_can( 'delete_term', $tag->term_id ) ) : ?>
  248. <span id="delete-link">
  249. <a class="delete" href="<?php echo admin_url( wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) ) ?>"><?php _e( 'Delete' ); ?></a>
  250. </span>
  251. <?php endif; ?>
  252. </div>
  253. </form>
  254. </div>
  255. <?php if ( ! wp_is_mobile() ) : ?>
  256. <script type="text/javascript">
  257. try{document.forms.edittag.name.focus();}catch(e){}
  258. </script>
  259. <?php endif;