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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / forms / form-taxonomy.php
advanced-custom-fields / includes / forms Last commit date
form-attachment.php 5 months ago form-comment.php 4 weeks ago form-customizer.php 5 months ago form-front.php 2 months ago form-gutenberg.php 5 months ago form-nav-menu.php 5 months ago form-post.php 3 months ago form-taxonomy.php 2 months ago form-user.php 4 weeks ago form-widget.php 5 months ago index.php 2 years ago
form-taxonomy.php
363 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! class_exists( 'acf_form_taxonomy' ) ) :
13
14 class acf_form_taxonomy {
15
16 var $view = 'add';
17
18
19 /**
20 * This function will setup the class functionality
21 *
22 * @type function
23 * @date 5/03/2014
24 * @since 5.0.0
25 *
26 * @param n/a
27 * @return n/a
28 */
29 function __construct() {
30
31 // actions
32 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
33
34 // save
35 add_action( 'create_term', array( $this, 'save_term' ), 10, 3 );
36 add_action( 'edit_term', array( $this, 'save_term' ), 10, 3 );
37
38 // delete
39 add_action( 'delete_term', array( $this, 'delete_term' ), 10, 4 );
40 }
41
42
43 /**
44 * This function will check if the current page is for a post/page edit form
45 *
46 * @type function
47 * @date 23/06/12
48 * @since 3.1.8
49 *
50 * @param n/a
51 * @return (boolean)
52 */
53 function validate_page() {
54
55 // global
56 global $pagenow;
57
58 // validate page
59 if ( $pagenow === 'edit-tags.php' || $pagenow === 'term.php' ) {
60 return true;
61 }
62
63 // return
64 return false;
65 }
66
67
68 /**
69 * This action is run after post query but before any admin script / head actions.
70 * It is a good place to register all actions.
71 *
72 * @type action (admin_enqueue_scripts)
73 * @date 26/01/13
74 * @since 3.6.0
75 *
76 * @param N/A
77 * @return N/A
78 */
79 function admin_enqueue_scripts() {
80
81 // validate page
82 if ( ! $this->validate_page() ) {
83 return;
84 }
85
86 // vars
87 $screen = get_current_screen();
88 $taxonomy = $screen->taxonomy;
89
90 // load acf scripts
91 acf_enqueue_scripts();
92
93 // actions
94 add_action( 'admin_footer', array( $this, 'admin_footer' ), 10, 1 );
95 add_action( "{$taxonomy}_add_form_fields", array( $this, 'add_term' ), 10, 1 );
96 add_action( "{$taxonomy}_edit_form", array( $this, 'edit_term' ), 10, 2 );
97 }
98
99
100 /**
101 * description
102 *
103 * @type function
104 * @date 8/10/13
105 * @since 5.0.0
106 *
107 * @param $post_id (int)
108 * @return $post_id (int)
109 */
110 function add_term( $taxonomy ) {
111
112 // vars
113 $post_id = 'term_0';
114
115 // update vars
116 $this->view = 'add';
117
118 // get field groups
119 $field_groups = acf_get_field_groups(
120 array(
121 'taxonomy' => $taxonomy,
122 )
123 );
124
125 // render
126 if ( ! empty( $field_groups ) ) {
127
128 // data
129 acf_form_data(
130 array(
131 'screen' => 'taxonomy',
132 'post_id' => $post_id,
133 )
134 );
135
136 // wrap
137 echo '<div id="acf-term-fields" class="acf-fields -clear">';
138
139 // loop
140 foreach ( $field_groups as $field_group ) {
141 $fields = acf_get_fields( $field_group );
142 acf_render_fields( $fields, $post_id, 'div', 'field' );
143 }
144
145 // wrap
146 echo '</div>';
147 }
148 }
149
150
151 /**
152 * description
153 *
154 * @type function
155 * @date 8/10/13
156 * @since 5.0.0
157 *
158 * @param $post_id (int)
159 * @return $post_id (int)
160 */
161 function edit_term( $term, $taxonomy ) {
162
163 // vars
164 $post_id = 'term_' . $term->term_id;
165
166 // update vars
167 $this->view = 'edit';
168
169 // get field groups
170 $field_groups = acf_get_field_groups(
171 array(
172 'taxonomy' => $taxonomy,
173 )
174 );
175
176 // render
177 if ( ! empty( $field_groups ) ) {
178 acf_form_data(
179 array(
180 'screen' => 'taxonomy',
181 'post_id' => $post_id,
182 )
183 );
184
185 foreach ( $field_groups as $field_group ) {
186 // title
187 if ( $field_group['style'] === 'default' ) {
188 echo '<h2>' . acf_esc_html( acf_get_field_group_title( $field_group ) ) . '</h2>';
189 }
190
191 // fields
192 echo '<table class="form-table">';
193 $fields = acf_get_fields( $field_group );
194 acf_render_fields( $fields, $post_id, 'tr', 'field' );
195 echo '</table>';
196 }
197 }
198 }
199
200
201 /**
202 * description
203 *
204 * @type function
205 * @date 27/03/2015
206 * @since 5.1.5
207 *
208 * @param $post_id (int)
209 * @return $post_id (int)
210 */
211 function admin_footer() {
212
213 ?>
214 <script type="text/javascript">
215 (function($) {
216
217 // Define vars.
218 var view = '<?php echo esc_attr( $this->view ); ?>';
219 var $form = $('#' + view + 'tag');
220 var $submit = $('#' + view + 'tag input[type="submit"]:last');
221
222 // Add missing spinner.
223 if( !$submit.next('.spinner').length ) {
224 $submit.after('<span class="spinner"></span>');
225 }
226
227 <?php
228
229 // View: Add.
230 if ( $this->view == 'add' ) :
231 ?>
232
233 // vars
234 var $fields = $('#acf-term-fields');
235 var html = '';
236
237 // Store a copy of the $fields html used later to replace after AJAX request.
238 // Hook into 'prepare' action to allow ACF core helpers to first modify DOM.
239 // Fixes issue where hidden #acf-hidden-wp-editor is initialized again.
240 acf.addAction('prepare', function(){
241 html = $fields.html();
242 }, 6);
243
244 // WP triggers click as primary action
245 $submit.on('click', function( e ){
246
247 // validate
248 var valid = acf.validateForm({
249 form: $form,
250 event: e,
251 reset: true
252 });
253
254 // if not valid, stop event and allow validation to continue
255 if( !valid ) {
256 e.preventDefault();
257 e.stopImmediatePropagation();
258 }
259 });
260
261 // listen to AJAX add-tag complete
262 $(document).ajaxComplete(function(event, xhr, settings) {
263
264 // bail early if is other ajax call
265 if( settings.data.indexOf('action=add-tag') == -1 ) {
266 return;
267 }
268
269 // bail early if response contains error
270 if( xhr.responseText.indexOf('wp_error') !== -1 ) {
271 return;
272 }
273
274 // action for 3rd party customization
275 acf.doAction('remove', $fields);
276
277 // reset HTML
278 $fields.html( html );
279
280 // action for 3rd party customization
281 acf.doAction('append', $fields);
282
283 // reset unload
284 acf.unload.reset();
285 });
286
287 <?php endif; ?>
288
289 })(jQuery);
290 </script>
291 <?php
292 }
293
294
295 /**
296 * description
297 *
298 * @type function
299 * @date 8/10/13
300 * @since 5.0.0
301 *
302 * @param $post_id (int)
303 * @return $post_id (int)
304 */
305 function save_term( $term_id, $tt_id, $taxonomy ) {
306
307 // vars
308 $post_id = 'term_' . $term_id;
309
310 // verify and remove nonce
311 if ( ! acf_verify_nonce( 'taxonomy' ) ) {
312 return $term_id;
313 }
314
315 // valied and show errors
316 acf_validate_save_post( true );
317
318 // save
319 acf_save_post( $post_id );
320 }
321
322
323 /**
324 * description
325 *
326 * @type function
327 * @date 15/10/13
328 * @since 5.0.0
329 *
330 * @param $post_id (int)
331 * @return $post_id (int)
332 */
333 function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) {
334
335 // bail early if termmeta table exists
336 if ( acf_isset_termmeta() ) {
337 return $term;
338 }
339
340 // globals
341 global $wpdb;
342
343 // vars
344 $search = $wpdb->esc_like( $taxonomy . '_' . $term . '_' ) . '%';
345 $_search = $wpdb->esc_like( '_' . $taxonomy . '_' . $term . '_' ) . '%';
346
347 // delete
348 $result = $wpdb->query(
349 $wpdb->prepare(
350 "DELETE FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s",
351 $search,
352 $_search
353 )
354 );
355 }
356 }
357
358 new acf_form_taxonomy();
359 endif;
360
361
362 ?>
363