PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta5
Secure Custom Fields v6.4.1-beta5
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / admin / post-types / admin-field-group.php
secure-custom-fields / includes / admin / post-types Last commit date
admin-field-group.php 1 year ago admin-field-groups.php 1 year ago admin-post-type.php 1 year ago admin-post-types.php 1 year ago admin-taxonomies.php 1 year ago admin-taxonomy.php 1 year ago class-acf-admin-ui-options-page.php 1 year ago class-acf-admin-ui-options-pages.php 1 year ago index.php 1 year ago
admin-field-group.php
597 lines
1 <?php
2 /**
3 * ACF Admin Field Group Class
4 *
5 * @class acf_admin_field_group
6 *
7 * @package ACF
8 * @subpackage Admin
9 */
10
11 if ( ! class_exists( 'acf_admin_field_group' ) ) :
12
13 /**
14 * ACF Admin Field Group Class
15 *
16 * All the logic for editing a field group
17 */
18 class acf_admin_field_group extends ACF_Admin_Internal_Post_Type {
19
20 /**
21 * The slug for the internal post type.
22 *
23 * @since ACF 6.1
24 * @var string
25 */
26 public $post_type = 'acf-field-group';
27
28 /**
29 * The admin body class used for the post type.
30 *
31 * @since ACF 6.1
32 * @var string
33 */
34 public $admin_body_class = 'acf-admin-single-field-group';
35
36 /**
37 * Constructs the class.
38 *
39 * @since ACF 5.0.0
40 */
41 public function __construct() {
42 parent::__construct();
43
44 add_action( 'wp_ajax_acf/field_group/render_field_settings', array( $this, 'ajax_render_field_settings' ) );
45 add_action( 'wp_ajax_acf/field_group/render_location_rule', array( $this, 'ajax_render_location_rule' ) );
46 add_action( 'wp_ajax_acf/field_group/move_field', array( $this, 'ajax_move_field' ) );
47 }
48
49 /**
50 * Customizes the messages shown when editing a field group.
51 *
52 * @since ACF 5.0.0
53 *
54 * @param array $messages Post type messages.
55 * @return array
56 */
57 public function post_updated_messages( $messages ) {
58 $messages['acf-field-group'] = array(
59 0 => '', // Unused. Messages start at index 1.
60 1 => __( 'Field group updated.', 'secure-custom-fields' ),
61 2 => __( 'Field group updated.', 'secure-custom-fields' ),
62 3 => __( 'Field group deleted.', 'secure-custom-fields' ),
63 4 => __( 'Field group updated.', 'secure-custom-fields' ),
64 5 => false, // field group does not support revisions.
65 6 => __( 'Field group published.', 'secure-custom-fields' ),
66 7 => __( 'Field group saved.', 'secure-custom-fields' ),
67 8 => __( 'Field group submitted.', 'secure-custom-fields' ),
68 9 => __( 'Field group scheduled for.', 'secure-custom-fields' ),
69 10 => __( 'Field group draft updated.', 'secure-custom-fields' ),
70 );
71
72 return $messages;
73 }
74
75 /**
76 * Enqueues any scripts necessary for internal post type.
77 *
78 * @since ACF 5.0.0
79 */
80 public function admin_enqueue_scripts() {
81 parent::admin_enqueue_scripts();
82
83 acf_localize_text(
84 array(
85 'The string "field_" may not be used at the start of a field name' => esc_html__( 'The string "field_" may not be used at the start of a field name', 'secure-custom-fields' ),
86 'This field cannot be moved until its changes have been saved' => esc_html__( 'This field cannot be moved until its changes have been saved', 'secure-custom-fields' ),
87 'Field group title is required' => esc_html__( 'Field group title is required', 'secure-custom-fields' ),
88 'Move field group to trash?' => esc_html__( 'Move field group to trash?', 'secure-custom-fields' ),
89 'No toggle fields available' => esc_html__( 'No toggle fields available', 'secure-custom-fields' ),
90 'Move Custom Field' => esc_html__( 'Move Custom Field', 'secure-custom-fields' ),
91 'Close modal' => esc_html__( 'Close modal', 'secure-custom-fields' ),
92 'Field moved to other group' => esc_html__( 'Field moved to other group', 'secure-custom-fields' ),
93 'Field groups linked successfully.' => esc_html__( 'Field groups linked successfully.', 'secure-custom-fields' ),
94 'Checked' => esc_html__( 'Checked', 'secure-custom-fields' ),
95 '(no label)' => esc_html__( '(no label)', 'secure-custom-fields' ),
96 '(this field)' => esc_html__( '(this field)', 'secure-custom-fields' ),
97 'copy' => esc_html__( 'copy', 'secure-custom-fields' ),
98 'or' => esc_html__( 'or', 'secure-custom-fields' ),
99 'Show this field group if' => esc_html__( 'Show this field group if', 'secure-custom-fields' ),
100 'Null' => esc_html__( 'Null', 'secure-custom-fields' ),
101 'PRO Only' => esc_html__( 'PRO Only', 'secure-custom-fields' ),
102
103 // Conditions.
104 'Has any value' => esc_html__( 'Has any value', 'secure-custom-fields' ),
105 'Has no value' => esc_html__( 'Has no value', 'secure-custom-fields' ),
106 'Value is equal to' => esc_html__( 'Value is equal to', 'secure-custom-fields' ),
107 'Value is not equal to' => esc_html__( 'Value is not equal to', 'secure-custom-fields' ),
108 'Value matches pattern' => esc_html__( 'Value matches pattern', 'secure-custom-fields' ),
109 'Value contains' => esc_html__( 'Value contains', 'secure-custom-fields' ),
110 'Value is greater than' => esc_html__( 'Value is greater than', 'secure-custom-fields' ),
111 'Value is less than' => esc_html__( 'Value is less than', 'secure-custom-fields' ),
112 'Selection is greater than' => esc_html__( 'Selection is greater than', 'secure-custom-fields' ),
113 'Selection is less than' => esc_html__( 'Selection is less than', 'secure-custom-fields' ),
114 'Relationship is equal to' => esc_html__( 'Relationship is equal to', 'secure-custom-fields' ),
115 'Relationship is not equal to' => esc_html__( 'Relationship is not equal to', 'secure-custom-fields' ),
116 'Relationships contain' => esc_html__( 'Relationships contain', 'secure-custom-fields' ),
117 'Relationships do not contain' => esc_html__( 'Relationships do not contain', 'secure-custom-fields' ),
118 'Post is equal to' => esc_html__( 'Post is equal to', 'secure-custom-fields' ),
119 'Post is not equal to' => esc_html__( 'Post is not equal to', 'secure-custom-fields' ),
120 'Posts contain' => esc_html__( 'Posts contain', 'secure-custom-fields' ),
121 'Posts do not contain' => esc_html__( 'Posts do not contain', 'secure-custom-fields' ),
122 'Has any post selected' => esc_html__( 'Has any post selected', 'secure-custom-fields' ),
123 'Has no post selected' => esc_html__( 'Has no post selected', 'secure-custom-fields' ),
124 'Has any relationship selected' => esc_html__( 'Has any relationship selected', 'secure-custom-fields' ),
125 'Has no relationship selected' => esc_html__( 'Has no relationship selected', 'secure-custom-fields' ),
126 'Page is equal to' => esc_html__( 'Page is equal to', 'secure-custom-fields' ),
127 'Page is not equal to' => esc_html__( 'Page is not equal to', 'secure-custom-fields' ),
128 'Pages contain' => esc_html__( 'Pages contain', 'secure-custom-fields' ),
129 'Pages do not contain' => esc_html__( 'Pages do not contain', 'secure-custom-fields' ),
130 'Has any page selected' => esc_html__( 'Has any page selected', 'secure-custom-fields' ),
131 'Has no page selected' => esc_html__( 'Has no page selected', 'secure-custom-fields' ),
132 'User is equal to' => esc_html__( 'User is equal to', 'secure-custom-fields' ),
133 'User is not equal to' => esc_html__( 'User is not equal to', 'secure-custom-fields' ),
134 'Users contain' => esc_html__( 'Users contain', 'secure-custom-fields' ),
135 'Users do not contain' => esc_html__( 'Users do not contain', 'secure-custom-fields' ),
136 'Has any user selected' => esc_html__( 'Has any user selected', 'secure-custom-fields' ),
137 'Has no user selected' => esc_html__( 'Has no user selected', 'secure-custom-fields' ),
138 'Term is equal to' => esc_html__( 'Term is equal to', 'secure-custom-fields' ),
139 'Term is not equal to' => esc_html__( 'Term is not equal to', 'secure-custom-fields' ),
140 'Terms contain' => esc_html__( 'Terms contain', 'secure-custom-fields' ),
141 'Terms do not contain' => esc_html__( 'Terms do not contain', 'secure-custom-fields' ),
142 'Has any term selected' => esc_html__( 'Has any term selected', 'secure-custom-fields' ),
143 'Has no term selected' => esc_html__( 'Has no term selected', 'secure-custom-fields' ),
144
145 // Custom Select2 templates.
146 'Type to search...' => esc_html__( 'Type to search...', 'secure-custom-fields' ),
147 'This Field' => esc_html__( 'This Field', 'secure-custom-fields' ),
148 )
149 );
150
151 acf_localize_data(
152 array(
153 'fieldTypes' => acf_get_field_types_info(),
154 'fieldCategoriesL10n' => acf_get_field_categories_i18n(),
155 'PROUpgradeURL' => 'https://www.advancedcustomfields.com/pro/',
156 'PROFieldTypes' => acf_get_pro_field_types(),
157 'PROLocationTypes' => array(
158 'block' => esc_html__( 'Block', 'secure-custom-fields' ),
159 'options_page' => esc_html__( 'Options Page', 'secure-custom-fields' ),
160 ),
161 )
162 );
163
164 wp_enqueue_script( 'acf-pro-field-group' );
165 wp_enqueue_style( 'acf-pro-field-group' );
166
167 do_action( 'acf/field_group/admin_enqueue_scripts' );
168 }
169
170 /**
171 * Set up functionality for the field group edit page.
172 *
173 * @since ACF 3.1.8
174 */
175 public function admin_head() {
176 global $post, $field_group;
177
178 // Set global var.
179 $field_group = acf_get_field_group( $post->ID );
180
181 // metaboxes.
182 add_meta_box( 'acf-field-group-fields', __( 'Fields', 'secure-custom-fields' ), array( $this, 'mb_fields' ), 'acf-field-group', 'normal', 'high' );
183 add_meta_box( 'acf-field-group-options', __( 'Settings', 'secure-custom-fields' ), array( $this, 'mb_options' ), 'acf-field-group', 'normal', 'high' );
184
185 // actions.
186 add_action( 'post_submitbox_misc_actions', array( $this, 'post_submitbox_misc_actions' ), 10, 0 );
187 add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ), 10, 0 );
188
189 // filters.
190 add_filter( 'screen_settings', array( $this, 'screen_settings' ), 10, 1 );
191 add_filter( 'get_user_option_screen_layout_acf-field-group', array( $this, 'screen_layout' ), 10, 1 );
192
193 // 3rd party hook.
194 do_action( 'acf/field_group/admin_head' );
195 }
196
197 /**
198 * This action will allow ACF to render metaboxes after the title.
199 */
200 public function edit_form_after_title() {
201 global $post;
202
203 // Render post data.
204 acf_form_data(
205 array(
206 'screen' => 'field_group',
207 'post_id' => $post->ID,
208 'delete_fields' => 0,
209 'validation' => 0,
210 )
211 );
212 }
213
214 /**
215 * This function will add extra HTML to the acf form data element
216 *
217 * @since ACF 5.3.8
218 *
219 * @param array $args Arguments array to pass through to action.
220 * @return void
221 */
222 public function form_data( $args ) {
223 do_action( 'acf/field_group/form_data', $args );
224 }
225
226 /**
227 * This function will append extra l10n strings to the acf JS object
228 *
229 * @since ACF 5.3.8
230 *
231 * @param array $l10n The array of translated strings.
232 * @return array $l10n
233 */
234 public function admin_l10n( $l10n ) {
235 return apply_filters( 'acf/field_group/admin_l10n', $l10n );
236 }
237
238 /**
239 * Admin footer third party hook support
240 *
241 * @since ACF 5.3.2
242 */
243 public function admin_footer() {
244 do_action( 'acf/field_group/admin_footer' );
245 }
246
247 /**
248 * Screen settings html output
249 *
250 * @since ACF 3.6.0
251 *
252 * @param string $html Current screen settings HTML.
253 * @return string $html
254 */
255 public function screen_settings( $html ) {
256 $show_field_keys = acf_get_user_setting( 'show_field_keys' ) ? 'checked="checked"' : '';
257 $show_field_settings_tabs = acf_get_user_setting( 'show_field_settings_tabs', true ) ? 'checked="checked"' : '';
258 $hide_field_settings_tabs = apply_filters( 'acf/field_group/disable_field_settings_tabs', false );
259
260 $html .= '<div id="acf-append-show-on-screen" class="acf-hidden">';
261 $html .= '<label for="acf-field-key-hide"><input id="acf-field-key-hide" type="checkbox" value="1" name="show_field_keys" ' . $show_field_keys . ' /> ' . __( 'Field Keys', 'secure-custom-fields' ) . '</label>';
262
263 if ( ! $hide_field_settings_tabs ) {
264 $html .= '<label for="acf-field-settings-tabs"><input id="acf-field-settings-tabs" type="checkbox" value="1" name="show_field_settings_tabs" ' . $show_field_settings_tabs . ' />' . __( 'Field Settings Tabs', 'secure-custom-fields' ) . '</label>';
265 }
266
267 $html .= '</div>';
268
269 return $html;
270 }
271
272 /**
273 * Sets the "Edit Field Group" screen to use a one-column layout.
274 *
275 * @param integer $columns Number of columns for layout.
276 * @return integer
277 */
278 public function screen_layout( $columns = 0 ) {
279 return 1;
280 }
281
282 /**
283 * This function will customize the publish metabox
284 *
285 * @since ACF 5.2.9
286 */
287 public function post_submitbox_misc_actions() {
288 global $field_group;
289 $status_label = $field_group['active'] ? _x( 'Active', 'post status', 'secure-custom-fields' ) : _x( 'Inactive', 'post status', 'secure-custom-fields' );
290
291 ?>
292 <script type="text/javascript">
293 (function($) {
294 $('#post-status-display').html( '<?php echo esc_html( $status_label ); ?>' );
295 })(jQuery);
296 </script>
297 <?php
298 }
299
300 /**
301 * Saves field group data.
302 *
303 * @since ACF 1.0.0
304 *
305 * @param integer $post_id The post ID.
306 * @param WP_Post $post The post object.
307 * @return integer $post_id
308 */
309 public function save_post( $post_id, $post ) {
310 if ( ! $this->verify_save_post( $post_id, $post ) ) {
311 return $post_id;
312 }
313
314 // disable filters to ensure ACF loads raw data from DB.
315 acf_disable_filters();
316
317 // save fields.
318 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Validated by WordPress.
319 if ( ! empty( $_POST['acf_fields'] ) ) {
320
321 // loop.
322 foreach ( $_POST['acf_fields'] as $field ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized when saved.
323
324 if ( ! isset( $field['key'] ) ) {
325 continue;
326 }
327
328 // vars.
329 $specific = false;
330 $save = acf_extract_var( $field, 'save' );
331
332 // only saved field if has changed.
333 if ( $save == 'meta' ) {
334 $specific = array(
335 'menu_order',
336 'post_parent',
337 );
338 }
339
340 // set parent.
341 if ( ! $field['parent'] ) {
342 $field['parent'] = $post_id;
343 }
344
345 // save field.
346 acf_update_field( $field, $specific );
347 }
348 }
349
350 // delete fields.
351 if ( acf_maybe_get_POST( '_acf_delete_fields', false ) ) { // phpcs:ignore -- Sanitized below, unslash not needed
352
353 // clean.
354 $ids = explode( '|', $_POST['_acf_delete_fields'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Sanitized below, unslash not required.
355 $ids = array_map( 'intval', $ids );
356
357 // loop.
358 foreach ( $ids as $id ) {
359
360 // bai early if no id.
361 if ( ! $id ) {
362 continue;
363 }
364
365 // delete.
366 acf_delete_field( $id );
367 }
368 }
369
370 $_POST['acf_field_group']['ID'] = $post_id;
371 // phpcs:disable WordPress.Security.ValidatedSanitizedInput
372 $_POST['acf_field_group']['title'] = isset( $_POST['post_title'] ) ? $_POST['post_title'] : ''; // Post title is stored unsafe like WordPress, escaped on output.
373
374 // save field group.
375 acf_update_field_group( $_POST['acf_field_group'] );
376 // phpcs:enable WordPress.Security.ValidatedSanitizedInput
377 // phpcs:enable WordPress.Security.NonceVerification.Missing
378
379 return $post_id;
380 }
381
382 /**
383 * This function will render the HTML for the metabox 'acf-field-group-fields'
384 *
385 * @since ACF 5.0.0
386 */
387 public function mb_fields() {
388 global $field_group;
389
390 $view = array(
391 'fields' => acf_get_fields( $field_group ),
392 'parent' => 0,
393 );
394
395 acf_get_view( $this->post_type . '/fields', $view );
396 }
397
398 /**
399 * This function will render the HTML for the metabox 'acf-field-group-options'
400 *
401 * @since ACF 5.0.0
402 */
403 public function mb_options() {
404 global $field_group;
405
406 // Field group key (leave in for compatibility).
407 if ( ! acf_is_field_group_key( $field_group['key'] ) ) {
408 $field_group['key'] = uniqid( 'group_' );
409 }
410
411 acf_get_view( $this->post_type . '/options' );
412 }
413
414 /**
415 * This function can be accessed via an AJAX action and will return the result from the render_location_value function
416 *
417 * @since ACF 5.0.0
418 */
419 public function ajax_render_location_rule() {
420 // validate.
421 if ( ! acf_verify_ajax() ) {
422 die();
423 }
424
425 // verify user capability.
426 if ( ! acf_current_user_can_admin() ) {
427 die();
428 }
429
430 if ( empty( $_POST['rule'] ) ) {
431 die();
432 }
433
434 // validate rule.
435 $rule = acf_validate_location_rule( acf_sanitize_request_args( $_POST['rule'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- values not saved.
436
437 acf_get_view(
438 'acf-field-group/location-rule',
439 array(
440 'rule' => $rule,
441 )
442 );
443
444 die();
445 }
446
447 /**
448 * This function will return HTML containing the field's settings based on it's new type
449 *
450 * @since ACF 5.0.0
451 */
452 public function ajax_render_field_settings() {
453 // Verify the current request.
454 if ( ! acf_verify_ajax() || ! acf_current_user_can_admin() ) {
455 wp_send_json_error();
456 }
457
458 // Make sure we have a field.
459 $field = acf_maybe_get_POST( 'field' );
460 if ( ! $field ) {
461 wp_send_json_error();
462 }
463
464 $field['prefix'] = acf_maybe_get_POST( 'prefix' );
465 $field = acf_get_valid_field( $field );
466 $tabs = acf_get_combined_field_type_settings_tabs();
467 $tab_keys = array_keys( $tabs );
468 $sections = array();
469
470 foreach ( $tab_keys as $tab ) {
471 ob_start();
472
473 if ( 'general' === $tab ) {
474 // Back-compat for fields not using tab-specific hooks.
475 do_action( "acf/render_field_settings/type={$field['type']}", $field );
476 }
477
478 do_action( "acf/field_group/render_field_settings_tab/{$tab}/type={$field['type']}", $field );
479 do_action( "acf/render_field_{$tab}_settings/type={$field['type']}", $field );
480
481 $sections[ $tab ] = ob_get_clean();
482 }
483
484 wp_send_json_success( $sections );
485 }
486
487 /**
488 * Moves fields between field groups via AJAX.
489 *
490 * @since ACF 5.0.0
491 *
492 * @return void
493 */
494 public function ajax_move_field() {
495 // Disable filters to ensure ACF loads raw data from DB.
496 acf_disable_filters();
497
498 // phpcs:disable WordPress.Security.NonceVerification.Missing
499 $args = acf_parse_args(
500 $_POST,
501 array(
502 'nonce' => '',
503 'post_id' => 0,
504 'field_id' => 0,
505 'field_group_id' => 0,
506 )
507 );
508 // phpcs:enable WordPress.Security.NonceVerification.Missing
509
510 // Verify nonce.
511 if ( ! wp_verify_nonce( $args['nonce'], 'acf_nonce' ) ) {
512 die();
513 }
514
515 // Verify user capability.
516 if ( ! acf_current_user_can_admin() ) {
517 die();
518 }
519
520 // Move the field if the user has confirmed.
521 if ( $args['field_id'] && $args['field_group_id'] ) {
522 $field = acf_get_field( $args['field_id'] );
523 $old_field_group = acf_get_field_group( $args['post_id'] );
524 $new_field_group = acf_get_field_group( $args['field_group_id'] );
525
526 // Update the field parent and remove conditional logic.
527 $field['parent'] = $new_field_group['ID'];
528 $field['conditional_logic'] = 0;
529
530 // Update the field in the database.
531 acf_update_field( $field );
532
533 // Fire `acf/update_field_group` action hook so JSON can sync if necessary.
534 do_action( 'acf/update_field_group', $old_field_group );
535 do_action( 'acf/update_field_group', $new_field_group );
536
537 // Output HTML.
538 $link = '<a href="' . admin_url( 'post.php?post=' . $new_field_group['ID'] . '&action=edit' ) . '" target="_blank">' . esc_html( $new_field_group['title'] ) . '</a>';
539
540 echo '' .
541 '<p><strong>' . esc_html__( 'Move Complete.', 'secure-custom-fields' ) . '</strong></p>' .
542 '<p>' . sprintf(
543 /* translators: Confirmation message once a field has been moved to a different field group. */
544 acf_punctify( __( 'The %1$s field can now be found in the %2$s field group', 'secure-custom-fields' ) ),
545 esc_html( $field['label'] ),
546 $link //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
547 ) . '</p>' .
548 '<a href="#" class="button button-primary acf-close-popup">' . esc_html__( 'Close Modal', 'secure-custom-fields' ) . '</a>';
549 die();
550 }
551
552 // Get all field groups.
553 $field_groups = acf_get_field_groups();
554 $choices = array();
555
556 if ( ! empty( $field_groups ) ) {
557 foreach ( $field_groups as $field_group ) {
558 // Bail early if no ID.
559 if ( ! $field_group['ID'] ) {
560 continue;
561 }
562
563 // Bail early if is current.
564 if ( $field_group['ID'] == $args['post_id'] ) {
565 continue;
566 }
567
568 $choices[ $field_group['ID'] ] = $field_group['title'];
569 }
570 }
571
572 // Render options.
573 $field = acf_get_valid_field(
574 array(
575 'type' => 'select',
576 'name' => 'acf_field_group',
577 'choices' => $choices,
578 'aria-label' => __( 'Please select the destination for this field', 'secure-custom-fields' ),
579 )
580 );
581
582 echo '<p>' . esc_html__( 'Please select the destination for this field', 'secure-custom-fields' ) . '</p>';
583 echo '<form id="acf-move-field-form">';
584 acf_render_field_wrap( $field );
585 echo '<button type="submit" class="acf-btn">' . esc_html__( 'Move Field', 'secure-custom-fields' ) . '</button>';
586 echo '</form>';
587
588 die();
589 }
590 }
591
592 // initialize.
593 new acf_admin_field_group();
594 endif; // Class exists check.
595
596 ?>
597