field-advanced-link.php
3 months ago
field-button-group.php
1 week ago
field-button.php
7 months ago
field-checkbox.php
3 months ago
field-clone.php
2 years ago
field-code-editor.php
3 months ago
field-column.php
3 years ago
field-dynamic-render.php
3 years ago
field-file.php
3 months ago
field-flexible-content-actions-title.php
3 months ago
field-flexible-content-actions-toggle.php
3 months ago
field-flexible-content-actions.php
3 months ago
field-flexible-content-async.php
4 months ago
field-flexible-content-compatibility.php
3 months ago
field-flexible-content-controls.php
9 months ago
field-flexible-content-hide.php
3 months ago
field-flexible-content-hooks.php
9 months ago
field-flexible-content-modal-edit.php
9 months ago
field-flexible-content-modal-select.php
3 months ago
field-flexible-content-modal-settings.php
3 months ago
field-flexible-content-popup.php
3 months ago
field-flexible-content-preview.php
3 months ago
field-flexible-content-state.php
9 months ago
field-flexible-content-thumbnail.php
9 months ago
field-flexible-content-wysiwyg.php
9 months ago
field-flexible-content.php
3 months ago
field-forms.php
3 months ago
field-gallery.php
3 months ago
field-google-map.php
3 months ago
field-group.php
3 months ago
field-hidden.php
3 years ago
field-image.php
3 months ago
field-post-object.php
3 months ago
field-post-statuses.php
3 months ago
field-post-types.php
3 months ago
field-radio.php
3 months ago
field-recaptcha.php
3 months ago
field-relationship.php
3 months ago
field-repeater.php
3 months ago
field-select.php
3 months ago
field-slug.php
1 year ago
field-taxonomies.php
3 months ago
field-taxonomy-terms.php
3 months ago
field-taxonomy.php
3 months ago
field-textarea.php
3 months ago
field-user-roles.php
3 months ago
field-user.php
3 months ago
field-wysiwyg.php
3 months ago
field-flexible-content-actions.php
352 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_flexible_content_actions')): |
| 8 | |
| 9 | class acfe_field_flexible_content_actions{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | // Hooks |
| 17 | add_filter('acfe/flexible/defaults_field', array($this, 'defaults_field'), 6); |
| 18 | add_filter('acfe/flexible/render_field_settings', array($this, 'render_field_settings'), 6); |
| 19 | add_filter('acfe/flexible/wrapper_attributes', array($this, 'wrapper_attributes'), 10, 2); |
| 20 | add_filter('acfe/flexible/layouts/icons', array($this, 'layout_icons'), 11, 3); |
| 21 | add_filter('acfe/flexible/action_buttons', array($this, 'action_buttons'), 20, 3); |
| 22 | add_filter('acfe/flexible/secondary_actions', array($this, 'secondary_actions'), 10, 2); |
| 23 | add_filter('acfe/flexible/render_popup', array($this, 'render_popup_secondary_actions'), 10); |
| 24 | |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * defaults_field |
| 29 | * |
| 30 | * acfe/flexible/defaults_field |
| 31 | * |
| 32 | * @param $field |
| 33 | * |
| 34 | * @return mixed |
| 35 | */ |
| 36 | function defaults_field($field){ |
| 37 | |
| 38 | $field['acfe_flexible_add_actions'] = array(); |
| 39 | $field['acfe_flexible_close_button_label'] = ''; |
| 40 | |
| 41 | return $field; |
| 42 | |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * render_field_settings |
| 47 | * |
| 48 | * acfe/flexible/render_field_settings |
| 49 | * |
| 50 | * @param $field |
| 51 | */ |
| 52 | function render_field_settings($field){ |
| 53 | |
| 54 | $choices = array(); |
| 55 | |
| 56 | if(!acfe_is_acf('6.5')){ |
| 57 | $choices['title'] = __('Inline Title Edit', 'acfe'); |
| 58 | $choices['toggle'] = __('Toggle Layout', 'acfe'); |
| 59 | } |
| 60 | |
| 61 | $choices['copy'] = __('Copy/Paste Layout', 'acfe'); |
| 62 | $choices['lock'] = __('Lock Layouts', 'acfe'); |
| 63 | $choices['close'] = __('Close Layout Button', 'acfe'); |
| 64 | |
| 65 | if(!acfe_is_acf('5.9')){ |
| 66 | $choices['clone'] = __('Clone', 'acfe'); |
| 67 | } |
| 68 | |
| 69 | acf_render_field_setting($field, array( |
| 70 | 'label' => __('Additional Actions', 'acfe'), |
| 71 | 'name' => 'acfe_flexible_add_actions', |
| 72 | 'key' => 'acfe_flexible_add_actions', |
| 73 | 'instructions' => '<a href="https://www.acf-extended.com/features/fields/flexible-content/advanced-settings" target="_blank">' . __('See documentation', 'acfe') . '</a>', |
| 74 | 'type' => 'checkbox', |
| 75 | 'default_value' => '', |
| 76 | 'layout' => 'horizontal', |
| 77 | 'choices' => $choices, |
| 78 | 'conditional_logic' => array( |
| 79 | array( |
| 80 | array( |
| 81 | 'field' => 'acfe_flexible_advanced', |
| 82 | 'operator' => '==', |
| 83 | 'value' => '1', |
| 84 | ), |
| 85 | ) |
| 86 | ) |
| 87 | )); |
| 88 | |
| 89 | acf_render_field_setting($field, array( |
| 90 | 'label' => '', |
| 91 | 'name' => 'acfe_flexible_close_button_label', |
| 92 | 'key' => 'acfe_flexible_close_button_label', |
| 93 | 'instructions' => '', |
| 94 | 'type' => 'text', |
| 95 | 'default_value' => '', |
| 96 | 'prepend' => __('Close Label', 'acfe'), |
| 97 | 'placeholder' => __('Close', 'acfe'), |
| 98 | 'conditional_logic' => array( |
| 99 | array( |
| 100 | array( |
| 101 | 'field' => 'acfe_flexible_advanced', |
| 102 | 'operator' => '==', |
| 103 | 'value' => '1', |
| 104 | ), |
| 105 | array( |
| 106 | 'field' => 'acfe_flexible_add_actions', |
| 107 | 'operator' => '==', |
| 108 | 'value' => 'close', |
| 109 | ), |
| 110 | ) |
| 111 | ) |
| 112 | )); |
| 113 | |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /** |
| 118 | * wrapper_attributes |
| 119 | * |
| 120 | * acfe/flexible/wrapper_attributes |
| 121 | * |
| 122 | * @param $wrapper |
| 123 | * @param $field |
| 124 | * |
| 125 | * @return mixed |
| 126 | */ |
| 127 | function wrapper_attributes($wrapper, $field){ |
| 128 | |
| 129 | $actions = $field['acfe_flexible_add_actions']; |
| 130 | |
| 131 | // copy/paste |
| 132 | if(in_array('copy', $actions)){ |
| 133 | $wrapper['data-acfe-flexible-copy-paste'] = 1; |
| 134 | } |
| 135 | |
| 136 | // lock |
| 137 | if(in_array('lock', $actions)){ |
| 138 | |
| 139 | $lock = true; |
| 140 | $lock = apply_filters("acfe/flexible/lock", $lock, $field); |
| 141 | $lock = apply_filters("acfe/flexible/lock/name={$field['_name']}", $lock, $field); |
| 142 | $lock = apply_filters("acfe/flexible/lock/key={$field['key']}", $lock, $field); |
| 143 | |
| 144 | if($lock){ |
| 145 | $wrapper['data-acfe-flexible-lock'] = 1; |
| 146 | } |
| 147 | |
| 148 | } |
| 149 | |
| 150 | // close |
| 151 | if(in_array('close', $actions)){ |
| 152 | $wrapper['data-acfe-flexible-close-button'] = 1; |
| 153 | } |
| 154 | |
| 155 | return $wrapper; |
| 156 | |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * layout_icons |
| 161 | * |
| 162 | * acfe/flexible/layouts/icons |
| 163 | * |
| 164 | * @param $icons |
| 165 | * @param $layout |
| 166 | * @param $field |
| 167 | * |
| 168 | * @return mixed |
| 169 | */ |
| 170 | function layout_icons($icons, $layout, $field){ |
| 171 | |
| 172 | $actions = $field['acfe_flexible_add_actions']; |
| 173 | |
| 174 | // copy/paste |
| 175 | if(in_array('copy', $actions)){ |
| 176 | |
| 177 | // default icons |
| 178 | if(acfe_is_acf('6.5')){ |
| 179 | |
| 180 | // try to insert after 'add' icon |
| 181 | if(isset($icons['add'])){ |
| 182 | $icons = acfe_after($icons, 'add', array( |
| 183 | 'copy' => '<a class="acf-js-tooltip" href="#" data-name="acfe-copy-layout" title="'. __('Copy Layout', 'acfe') .'"><span class="acf-icon -copy"></span></a>' |
| 184 | )); |
| 185 | |
| 186 | // otherwise, prepend it at the beginning |
| 187 | }else{ |
| 188 | $icons = acfe_prepend($icons, array( |
| 189 | 'copy' => '<a class="acf-js-tooltip" href="#" data-name="acfe-copy-layout" title="'. __('Copy Layout', 'acfe') .'"><span class="acf-icon -copy"></span></a>', |
| 190 | )); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | }else{ |
| 195 | |
| 196 | $icons = acfe_prepend($icons, array( |
| 197 | 'copy' => '<a class="acf-icon small light acf-js-tooltip dashicons dashicons-upload" href="#" data-name="acfe-copy-layout" title="'. __('Copy layout', 'acfe') .'"></a>' |
| 198 | )); |
| 199 | |
| 200 | } |
| 201 | |
| 202 | } |
| 203 | |
| 204 | // clone |
| 205 | if(in_array('clone', $actions)){ |
| 206 | |
| 207 | // pre ACF 5.9 |
| 208 | if(!acfe_is_acf('5.9')){ |
| 209 | |
| 210 | $icons = acfe_append($icons, array( |
| 211 | 'clone' => '<a class="acf-icon small light acf-js-tooltip dashicons dashicons-admin-page" href="#" data-name="acfe-clone-layout" title="'. __('Clone layout', 'acfe'). '"></a>' |
| 212 | )); |
| 213 | |
| 214 | } |
| 215 | |
| 216 | } |
| 217 | |
| 218 | return $icons; |
| 219 | |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /** |
| 224 | * action_buttons |
| 225 | * |
| 226 | * @param $buttons |
| 227 | * @param $field |
| 228 | * @param $position |
| 229 | * |
| 230 | * @return void |
| 231 | */ |
| 232 | function action_buttons($buttons, $field, $position){ |
| 233 | |
| 234 | // check settings |
| 235 | if(!in_array('copy', $field['acfe_flexible_add_actions'])){ |
| 236 | return $buttons; |
| 237 | } |
| 238 | |
| 239 | // add button has been removed |
| 240 | if(!isset($buttons['add'])){ |
| 241 | return $buttons; |
| 242 | } |
| 243 | |
| 244 | // vars |
| 245 | $name = $field['_name']; |
| 246 | $key = $field['key']; |
| 247 | |
| 248 | // secondary buttons |
| 249 | $secondary_buttons = $this->get_secondary_buttons($field); |
| 250 | if(empty($secondary_buttons)){ |
| 251 | return $buttons; |
| 252 | } |
| 253 | |
| 254 | // button |
| 255 | $button = array( |
| 256 | 'href' => '#', |
| 257 | 'class' => 'acf-button button', |
| 258 | 'data-name' => 'acfe-secondary-actions', |
| 259 | ); |
| 260 | |
| 261 | // hooks |
| 262 | $button = apply_filters("acfe/flexible/action_button_secondary", $button, $field); |
| 263 | $button = apply_filters("acfe/flexible/action_button_secondary/name={$name}", $button, $field); |
| 264 | $button = apply_filters("acfe/flexible/action_button_secondary/key={$key}", $button, $field); |
| 265 | |
| 266 | // add button |
| 267 | $buttons['secondary'] = '<a ' . acf_esc_atts($button) . '><span class="dashicons dashicons-arrow-down-alt2"></span></a>'; |
| 268 | |
| 269 | // return |
| 270 | return $buttons; |
| 271 | |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /** |
| 276 | * secondary_actions |
| 277 | * |
| 278 | * acfe/flexible/secondary_actions |
| 279 | * |
| 280 | * @param $actions |
| 281 | * @param $field |
| 282 | * |
| 283 | * @return mixed |
| 284 | */ |
| 285 | function secondary_actions($actions, $field){ |
| 286 | |
| 287 | if(!in_array('copy', $field['acfe_flexible_add_actions'])){ |
| 288 | return $actions; |
| 289 | } |
| 290 | |
| 291 | $actions['copy'] = '<a href="#" data-name="acfe-copy-layouts">' . __('Copy layouts', 'acfe') . '</a>'; |
| 292 | $actions['paste'] = '<a href="#" data-name="acfe-paste-layouts">' . __('Paste layouts', 'acfe') . '</a>'; |
| 293 | |
| 294 | return $actions; |
| 295 | |
| 296 | } |
| 297 | |
| 298 | |
| 299 | /** |
| 300 | * render_popup_secondary_actions |
| 301 | * |
| 302 | * @param $field |
| 303 | * |
| 304 | * @return void |
| 305 | */ |
| 306 | function render_popup_secondary_actions($field){ |
| 307 | |
| 308 | // secondary buttons |
| 309 | $secondary_buttons = $this->get_secondary_buttons($field); |
| 310 | if(empty($secondary_buttons)){ |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | echo '<script type="text-html" class="tmpl-acfe-fc-secondary-popup">'; |
| 315 | |
| 316 | foreach($secondary_buttons as $button){ |
| 317 | echo '<li>' . $button . '</li>'; |
| 318 | } |
| 319 | |
| 320 | echo '</script>'; |
| 321 | |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /** |
| 326 | * get_secondary_buttons |
| 327 | * |
| 328 | * @param $field |
| 329 | * |
| 330 | * @return mixed|null |
| 331 | */ |
| 332 | function get_secondary_buttons($field){ |
| 333 | |
| 334 | // vars |
| 335 | $name = $field['_name']; |
| 336 | $key = $field['key']; |
| 337 | |
| 338 | // secondary buttons |
| 339 | $buttons = array(); |
| 340 | $buttons = apply_filters("acfe/flexible/secondary_actions", $buttons, $field); |
| 341 | $buttons = apply_filters("acfe/flexible/secondary_actions/name={$name}", $buttons, $field); |
| 342 | $buttons = apply_filters("acfe/flexible/secondary_actions/key={$key}", $buttons, $field); |
| 343 | |
| 344 | return $buttons; |
| 345 | |
| 346 | } |
| 347 | |
| 348 | } |
| 349 | |
| 350 | acf_new_instance('acfe_field_flexible_content_actions'); |
| 351 | |
| 352 | endif; |