field-advanced-link.php
1 month ago
field-button.php
6 months ago
field-checkbox.php
1 month ago
field-clone.php
2 years ago
field-code-editor.php
1 month ago
field-column.php
3 years ago
field-dynamic-render.php
3 years ago
field-file.php
1 month ago
field-flexible-content-actions-title.php
2 months ago
field-flexible-content-actions-toggle.php
1 month ago
field-flexible-content-actions.php
1 month ago
field-flexible-content-async.php
2 months ago
field-flexible-content-compatibility.php
1 month ago
field-flexible-content-controls.php
7 months ago
field-flexible-content-hide.php
1 month ago
field-flexible-content-hooks.php
7 months ago
field-flexible-content-modal-edit.php
7 months ago
field-flexible-content-modal-select.php
1 month ago
field-flexible-content-modal-settings.php
1 month ago
field-flexible-content-popup.php
2 months ago
field-flexible-content-preview.php
1 month ago
field-flexible-content-state.php
7 months ago
field-flexible-content-thumbnail.php
7 months ago
field-flexible-content-wysiwyg.php
7 months ago
field-flexible-content.php
1 month ago
field-forms.php
1 month ago
field-gallery.php
1 month ago
field-google-map.php
1 month ago
field-group.php
1 month ago
field-hidden.php
3 years ago
field-image.php
1 month ago
field-post-object.php
1 month ago
field-post-statuses.php
1 month ago
field-post-types.php
1 month ago
field-radio.php
1 month ago
field-recaptcha.php
2 months ago
field-relationship.php
1 month ago
field-repeater.php
1 month ago
field-select.php
1 month ago
field-slug.php
11 months ago
field-taxonomies.php
1 month ago
field-taxonomy-terms.php
1 month ago
field-taxonomy.php
1 month ago
field-textarea.php
1 month ago
field-user-roles.php
1 month ago
field-user.php
1 month ago
field-wysiwyg.php
1 month ago
field-clone.php
257 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_clone')): |
| 8 | |
| 9 | class acfe_field_clone extends acfe_field_extend{ |
| 10 | |
| 11 | /** |
| 12 | * initialize |
| 13 | */ |
| 14 | function initialize(){ |
| 15 | |
| 16 | $this->name = 'clone'; |
| 17 | $this->defaults = array( |
| 18 | 'acfe_seamless_style' => 0, |
| 19 | 'acfe_clone_modal' => 0, |
| 20 | 'acfe_clone_modal_close' => 0, |
| 21 | 'acfe_clone_modal_button' => '', |
| 22 | 'acfe_clone_modal_size' => 'large', |
| 23 | ); |
| 24 | |
| 25 | $this->add_action('wp_ajax_acf/fields/clone/query', array($this, 'ajax_query'), 5); |
| 26 | |
| 27 | } |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * ajax_query |
| 32 | * |
| 33 | * wp_ajax_acf/fields/clone/query |
| 34 | */ |
| 35 | function ajax_query(){ |
| 36 | |
| 37 | $nonce = acf_request_arg('nonce', ''); |
| 38 | |
| 39 | // validate |
| 40 | if(!acf_verify_ajax($nonce, 'acf/fields/clone/query')){ |
| 41 | die(); |
| 42 | } |
| 43 | |
| 44 | // local field groups are added at priority 20 |
| 45 | add_filter('acf/load_field_groups', array($this, 'ajax_load_field_groups'), 25); |
| 46 | |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * ajax_load_field_groups |
| 52 | * |
| 53 | * @param $field_groups |
| 54 | * |
| 55 | * @return mixed |
| 56 | */ |
| 57 | function ajax_load_field_groups($field_groups){ |
| 58 | |
| 59 | // get reserved field groups |
| 60 | $hidden = acfe_get_setting('reserved_field_groups', array()); |
| 61 | |
| 62 | // loop |
| 63 | foreach($field_groups as $i => $field_group){ |
| 64 | |
| 65 | // hide |
| 66 | if(in_array($field_group['key'], $hidden)){ |
| 67 | unset($field_groups[ $i ]); |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | return $field_groups; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * render_field_settings |
| 79 | * |
| 80 | * @param $field |
| 81 | */ |
| 82 | function render_field_settings($field){ |
| 83 | |
| 84 | // seamless style |
| 85 | acf_render_field_setting($field, array( |
| 86 | 'label' => __('Seamless Style', 'acfe'), |
| 87 | 'name' => 'acfe_seamless_style', |
| 88 | 'key' => 'acfe_seamless_style', |
| 89 | 'instructions' => __('Enable better CSS integration: remove borders and padding'), |
| 90 | 'type' => 'true_false', |
| 91 | 'message' => '', |
| 92 | 'default_value' => false, |
| 93 | 'ui' => true, |
| 94 | 'conditional_logic' => array( |
| 95 | array( |
| 96 | array( |
| 97 | 'field' => 'display', |
| 98 | 'operator' => '==', |
| 99 | 'value' => 'group', |
| 100 | ), |
| 101 | array( |
| 102 | 'field' => 'acfe_clone_modal', |
| 103 | 'operator' => '!=', |
| 104 | 'value' => '1', |
| 105 | ) |
| 106 | ) |
| 107 | ) |
| 108 | )); |
| 109 | |
| 110 | // edit modal |
| 111 | acf_render_field_setting($field, array( |
| 112 | 'label' => __('Edition modal'), |
| 113 | 'name' => 'acfe_clone_modal', |
| 114 | 'key' => 'acfe_clone_modal', |
| 115 | 'instructions' => __('Edit fields in a modal'), |
| 116 | 'type' => 'true_false', |
| 117 | 'message' => '', |
| 118 | 'default_value' => false, |
| 119 | 'ui' => true, |
| 120 | 'conditional_logic' => array( |
| 121 | array( |
| 122 | array( |
| 123 | 'field' => 'display', |
| 124 | 'operator' => '==', |
| 125 | 'value' => 'group', |
| 126 | ), |
| 127 | array( |
| 128 | 'field' => 'acfe_seamless_style', |
| 129 | 'operator' => '!=', |
| 130 | 'value' => '1', |
| 131 | ) |
| 132 | ), |
| 133 | ) |
| 134 | )); |
| 135 | |
| 136 | // modal close |
| 137 | acf_render_field_setting($field, array( |
| 138 | 'label' => __('Edition modal: Close button'), |
| 139 | 'name' => 'acfe_clone_modal_close', |
| 140 | 'key' => 'acfe_clone_modal_close', |
| 141 | 'instructions' => __('Display close button'), |
| 142 | 'type' => 'true_false', |
| 143 | 'message' => '', |
| 144 | 'default_value' => false, |
| 145 | 'ui' => true, |
| 146 | 'conditional_logic' => array( |
| 147 | array( |
| 148 | array( |
| 149 | 'field' => 'acfe_clone_modal', |
| 150 | 'operator' => '==', |
| 151 | 'value' => '1', |
| 152 | ), |
| 153 | ) |
| 154 | ) |
| 155 | )); |
| 156 | |
| 157 | // modal button |
| 158 | acf_render_field_setting($field, array( |
| 159 | 'label' => __('Edition modal: Text button'), |
| 160 | 'name' => 'acfe_clone_modal_button', |
| 161 | 'key' => 'acfe_clone_modal_button', |
| 162 | 'instructions' => __('Text displayed in the edition modal button'), |
| 163 | 'type' => 'text', |
| 164 | 'placeholder' => __('Edit', 'acf'), |
| 165 | 'conditional_logic' => array( |
| 166 | array( |
| 167 | array( |
| 168 | 'field' => 'acfe_clone_modal', |
| 169 | 'operator' => '==', |
| 170 | 'value' => '1', |
| 171 | ), |
| 172 | ) |
| 173 | ) |
| 174 | )); |
| 175 | |
| 176 | // modal size |
| 177 | acf_render_field_setting($field, array( |
| 178 | 'label' => __('Edition modal: Size'), |
| 179 | 'name' => 'acfe_clone_modal_size', |
| 180 | 'key' => 'acfe_clone_modal_size', |
| 181 | 'instructions' => __('Choose the modal size'), |
| 182 | 'type' => 'select', |
| 183 | 'choices' => array( |
| 184 | 'small' => 'Small', |
| 185 | 'medium' => 'Medium', |
| 186 | 'large' => 'Large', |
| 187 | 'xlarge' => 'Extra Large', |
| 188 | 'full' => 'Full', |
| 189 | ), |
| 190 | 'default_value' => 'large', |
| 191 | 'conditional_logic' => array( |
| 192 | array( |
| 193 | array( |
| 194 | 'field' => 'acfe_clone_modal', |
| 195 | 'operator' => '==', |
| 196 | 'value' => '1', |
| 197 | ), |
| 198 | ) |
| 199 | ) |
| 200 | )); |
| 201 | |
| 202 | } |
| 203 | |
| 204 | |
| 205 | /** |
| 206 | * prepare_field |
| 207 | * |
| 208 | * @param $field |
| 209 | * |
| 210 | * @return array |
| 211 | */ |
| 212 | function prepare_field($field){ |
| 213 | |
| 214 | // seamless style |
| 215 | if($field['acfe_seamless_style']){ |
| 216 | $field['wrapper']['class'] .= ' acfe-seamless-style'; |
| 217 | } |
| 218 | |
| 219 | // layout |
| 220 | if($field['layout']){ |
| 221 | $field['wrapper']['class'] .= ' acfe-field-clone-layout-' . $field['layout']; |
| 222 | } |
| 223 | |
| 224 | // edit modal |
| 225 | if($field['acfe_clone_modal']){ |
| 226 | |
| 227 | $field['wrapper']['data-acfe-clone-modal'] = 1; |
| 228 | $field['wrapper']['data-acfe-clone-modal-button'] = $field['acfe_clone_modal_button'] ? $field['acfe_clone_modal_button'] : __('Edit', 'acf'); |
| 229 | $field['wrapper']['data-acfe-clone-modal-close'] = $field['acfe_clone_modal_close']; |
| 230 | $field['wrapper']['data-acfe-clone-modal-size'] = $field['acfe_clone_modal_size']; |
| 231 | |
| 232 | } |
| 233 | |
| 234 | // return |
| 235 | return $field; |
| 236 | |
| 237 | } |
| 238 | |
| 239 | |
| 240 | /** |
| 241 | * translate_field |
| 242 | * |
| 243 | * @param $field |
| 244 | */ |
| 245 | function translate_field($field){ |
| 246 | |
| 247 | $field['acfe_clone_modal_button'] = acf_translate($field['acfe_clone_modal_button']); |
| 248 | |
| 249 | return $field; |
| 250 | |
| 251 | } |
| 252 | |
| 253 | } |
| 254 | |
| 255 | acf_new_instance('acfe_field_clone'); |
| 256 | |
| 257 | endif; |