field-advanced-link.php
6 years ago
field-button.php
6 years ago
field-clone.php
6 years ago
field-column.php
6 years ago
field-dynamic-message.php
6 years ago
field-file.php
6 years ago
field-flexible-content.php
6 years ago
field-forms.php
6 years ago
field-group.php
6 years ago
field-hidden.php
6 years ago
field-image.php
6 years ago
field-post-statuses.php
6 years ago
field-post-types.php
6 years ago
field-recaptcha.php
6 years ago
field-repeater.php
6 years ago
field-select.php
6 years ago
field-slug.php
6 years ago
field-taxonomies.php
6 years ago
field-taxonomy-terms.php
6 years ago
field-textarea.php
6 years ago
field-user-roles.php
6 years ago
field-clone.php
103 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | add_action('acf/render_field_settings/type=clone', 'acfe_field_clone_settings'); |
| 7 | function acfe_field_clone_settings($field){ |
| 8 | |
| 9 | acf_render_field_setting($field, array( |
| 10 | 'label' => __('Edition modal'), |
| 11 | 'name' => 'acfe_clone_modal', |
| 12 | 'key' => 'acfe_clone_modal', |
| 13 | 'instructions' => __('Edit fields in a modal'), |
| 14 | 'type' => 'true_false', |
| 15 | 'message' => '', |
| 16 | 'default_value' => false, |
| 17 | 'ui' => true, |
| 18 | )); |
| 19 | |
| 20 | acf_render_field_setting($field, array( |
| 21 | 'label' => __('Edition modal button'), |
| 22 | 'name' => 'acfe_clone_modal_button', |
| 23 | 'key' => 'acfe_clone_modal_button', |
| 24 | 'instructions' => __('Text displayed in the edition modal button'), |
| 25 | 'type' => 'text', |
| 26 | 'placeholder' => __('Edit', 'acf'), |
| 27 | 'conditional_logic' => array( |
| 28 | array( |
| 29 | array( |
| 30 | 'field' => 'acfe_clone_modal', |
| 31 | 'operator' => '==', |
| 32 | 'value' => '1', |
| 33 | ), |
| 34 | ) |
| 35 | ) |
| 36 | )); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | add_filter('acf/field_wrapper_attributes', 'acfe_field_clone_wrapper', 10, 2); |
| 41 | function acfe_field_clone_wrapper($wrapper, $field){ |
| 42 | |
| 43 | if($field['type'] !== 'clone') |
| 44 | return $wrapper; |
| 45 | |
| 46 | if(isset($field['acfe_clone_modal']) && !empty($field['acfe_clone_modal'])){ |
| 47 | |
| 48 | $wrapper['data-acfe-clone-modal'] = 1; |
| 49 | $wrapper['data-acfe-clone-modal-button'] = __('Edit', 'acf'); |
| 50 | |
| 51 | if(isset($field['acfe_clone_modal_button']) && !empty($field['acfe_clone_modal_button'])){ |
| 52 | |
| 53 | $wrapper['data-acfe-clone-modal-button'] = $field['acfe_clone_modal_button']; |
| 54 | |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | |
| 59 | return $wrapper; |
| 60 | |
| 61 | } |
| 62 | |
| 63 | add_filter('acf/load_field_groups', 'acfe_field_clone_ajax_query'); |
| 64 | function acfe_field_clone_ajax_query($field_groups){ |
| 65 | |
| 66 | if(!acf_verify_ajax()) |
| 67 | return $field_groups; |
| 68 | |
| 69 | if(acf_maybe_get_POST('field_key') !== 'clone') |
| 70 | return $field_groups; |
| 71 | |
| 72 | if(empty($field_groups)) |
| 73 | return $field_groups; |
| 74 | |
| 75 | foreach($field_groups as $i => $field_group){ |
| 76 | |
| 77 | if(!in_array($field_group['key'], array( |
| 78 | 'group_acfe_author', |
| 79 | 'group_acfe_dynamic_block_type', |
| 80 | 'group_acfe_dynamic_form', |
| 81 | 'group_acfe_dynamic_options_page', |
| 82 | 'group_acfe_dynamic_post_type', |
| 83 | 'group_acfe_dynamic_taxonomy') |
| 84 | )) |
| 85 | continue; |
| 86 | |
| 87 | unset($field_groups[$i]); |
| 88 | |
| 89 | } |
| 90 | |
| 91 | return $field_groups; |
| 92 | |
| 93 | } |
| 94 | |
| 95 | add_filter('acf/prepare_field/type=clone', 'acfe_field_clone_type_class', 99); |
| 96 | function acfe_field_clone_type_class($field){ |
| 97 | |
| 98 | if(acf_maybe_get($field, 'layout')) |
| 99 | $field['wrapper']['class'] .= ' acfe-field-clone-layout-' . $field['layout']; |
| 100 | |
| 101 | return $field; |
| 102 | |
| 103 | } |