edit-tag-form.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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_http_referer ); ?>"><?php
  70. /* translators: %s: taxonomy name */
  71. printf( _x( '&larr; Back to %s', 'admin screen' ), $tax->labels->name );
  72. ?></a></p>
  73. <?php } ?>
  74. </div>
  75. <?php endif; ?>
  76. <div id="ajax-response"></div>
  77. <form name="edittag" id="edittag" method="post" action="edit-tags.php" class="validate"<?php
  78. /**
  79. * Fires inside the Edit Term form tag.
  80. *
  81. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
  82. *
  83. * @since 3.7.0
  84. */
  85. do_action( "{$taxonomy}_term_edit_form_tag" );
  86. ?>>
  87. <input type="hidden" name="action" value="editedtag"/>
  88. <input type="hidden" name="tag_ID" value="<?php echo esc_attr( $tag_ID ) ?>"/>
  89. <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ) ?>"/>
  90. <?php
  91. wp_original_referer_field( true, 'previous' );
  92. wp_nonce_field( 'update-tag_' . $tag_ID );
  93. /**
  94. * Fires at the beginning of the Edit Term form.
  95. *
  96. * At this point, the required hidden fields and nonces have already been output.
  97. *
  98. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
  99. *
  100. * @since 4.5.0
  101. *
  102. * @param object $tag Current taxonomy term object.
  103. * @param string $taxonomy Current $taxonomy slug.
  104. */
  105. do_action( "{$taxonomy}_term_edit_form_top", $tag, $taxonomy );
  106. ?>
  107. <table class="form-table">
  108. <tr class="form-field form-required term-name-wrap">
  109. <th scope="row"><label for="name"><?php _ex( 'Name', 'term name' ); ?></label></th>
  110. <td><input name="name" id="name" type="text" value="<?php if ( isset( $tag->name ) ) echo esc_attr($tag->name); ?>" size="40" aria-required="true" />
  111. <p class="description"><?php _e('The name is how it appears on your site.'); ?></p></td>
  112. </tr>
  113. <?php if ( !global_terms_enabled() ) { ?>
  114. <tr class="form-field term-slug-wrap">
  115. <th scope="row"><label for="slug"><?php _e( 'Slug' ); ?></label></th>
  116. <?php
  117. /**
  118. * Filters the editable slug.
  119. *
  120. * Note: This is a multi-use hook in that it is leveraged both for editable
  121. * post URIs and term slugs.
  122. *
  123. * @since 2.6.0
  124. * @since 4.4.0 The `$tag` parameter was added.
  125. *
  126. * @param string $slug The editable slug. Will be either a term slug or post URI depending
  127. * upon the context in which it is evaluated.
  128. * @param object|WP_Post $tag Term or WP_Post object.
  129. */
  130. $slug = isset( $tag->slug ) ? apply_filters( 'editable_slug', $tag->slug, $tag ) : '';
  131. ?>
  132. <td><input name="slug" id="slug" type="text" value="<?php echo esc_attr( $slug ); ?>" size="40" />
  133. <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>
  134. </tr>
  135. <?php } ?>
  136. <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
  137. <tr class="form-field term-parent-wrap">
  138. <th scope="row"><label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label></th>
  139. <td>
  140. <?php
  141. $dropdown_args = array(
  142. 'hide_empty' => 0,
  143. 'hide_if_empty' => false,
  144. 'taxonomy' => $taxonomy,
  145. 'name' => 'parent',
  146. 'orderby' => 'name',
  147. 'selected' => $tag->parent,
  148. 'exclude_tree' => $tag->term_id,
  149. 'hierarchical' => true,
  150. 'show_option_none' => __( 'None' ),
  151. );
  152. /** This filter is documented in wp-admin/edit-tags.php */
  153. $dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'edit' );
  154. wp_dropdown_categories( $dropdown_args ); ?>
  155. <?php if ( 'category' == $taxonomy ) : ?>
  156. <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>
  157. <?php else : ?>
  158. <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>
  159. <?php endif; ?>
  160. </td>
  161. </tr>
  162. <?php endif; // is_taxonomy_hierarchical() ?>
  163. <tr class="form-field term-description-wrap">
  164. <th scope="row"><label for="description"><?php _e( 'Description' ); ?></label></th>
  165. <td><textarea name="description" id="description" rows="5" cols="50" class="large-text"><?php echo $tag->description; // textarea_escaped ?></textarea>
  166. <p class="description"><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p></td>
  167. </tr>
  168. <?php
  169. // Back compat hooks
  170. if ( 'category' == $taxonomy ) {
  171. /**
  172. * Fires after the Edit Category form fields are displayed.
  173. *
  174. * @since 2.9.0
  175. * @deprecated 3.0.0 Use {$taxonomy}_edit_form_fields instead.
  176. *
  177. * @param object $tag Current category term object.
  178. */
  179. do_action( 'edit_category_form_fields', $tag );
  180. } elseif ( 'link_category' == $taxonomy ) {
  181. /**
  182. * Fires after the Edit Link Category form fields are displayed.
  183. *
  184. * @since 2.9.0
  185. * @deprecated 3.0.0 Use {$taxonomy}_edit_form_fields instead.
  186. *
  187. * @param object $tag Current link category term object.
  188. */
  189. do_action( 'edit_link_category_form_fields', $tag );
  190. } else {
  191. /**
  192. * Fires after the Edit Tag form fields are displayed.
  193. *
  194. * @since 2.9.0
  195. * @deprecated 3.0.0 Use {$taxonomy}_edit_form_fields instead.
  196. *
  197. * @param object $tag Current tag term object.
  198. */
  199. do_action( 'edit_tag_form_fields', $tag );
  200. }
  201. /**
  202. * Fires after the Edit Term form fields are displayed.
  203. *
  204. * The dynamic portion of the hook name, `$taxonomy`, refers to
  205. * the taxonomy slug.
  206. *
  207. * @since 3.0.0
  208. *
  209. * @param object $tag Current taxonomy term object.
  210. * @param string $taxonomy Current taxonomy slug.
  211. */
  212. do_action( "{$taxonomy}_edit_form_fields", $tag, $taxonomy );
  213. ?>
  214. </table>
  215. <?php
  216. // Back compat hooks
  217. if ( 'category' == $taxonomy ) {
  218. /** This action is documented in wp-admin/edit-tags.php */
  219. do_action( 'edit_category_form', $tag );
  220. } elseif ( 'link_category' == $taxonomy ) {
  221. /** This action is documented in wp-admin/edit-tags.php */
  222. do_action( 'edit_link_category_form', $tag );
  223. } else {
  224. /**
  225. * Fires at the end of the Edit Term form.
  226. *
  227. * @since 2.5.0
  228. * @deprecated 3.0.0 Use {$taxonomy}_edit_form instead.
  229. *
  230. * @param object $tag Current taxonomy term object.
  231. */
  232. do_action( 'edit_tag_form', $tag );
  233. }
  234. /**
  235. * Fires at the end of the Edit Term form for all taxonomies.
  236. *
  237. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
  238. *
  239. * @since 3.0.0
  240. *
  241. * @param object $tag Current taxonomy term object.
  242. * @param string $taxonomy Current taxonomy slug.
  243. */
  244. do_action( "{$taxonomy}_edit_form", $tag, $taxonomy );
  245. ?>
  246. <div class="edit-tag-actions">
  247. <?php submit_button( __( 'Update' ), 'primary', null, false ); ?>
  248. <?php if ( current_user_can( 'delete_term', $tag->term_id ) ) : ?>
  249. <span id="delete-link">
  250. <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>
  251. </span>
  252. <?php endif; ?>
  253. </div>
  254. </form>
  255. </div>
  256. <?php if ( ! wp_is_mobile() ) : ?>
  257. <script type="text/javascript">
  258. try{document.forms.edittag.name.focus();}catch(e){}
  259. </script>
  260. <?php endif;