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-state.php
233 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_flexible_content_state')): |
| 8 | |
| 9 | class acfe_field_flexible_content_state{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | // Hooks |
| 17 | add_filter('acfe/flexible/defaults_field', array($this, 'defaults_field'), 8); |
| 18 | add_action('acfe/flexible/render_field_settings', array($this, 'render_field_settings'), 8); |
| 19 | add_filter('acfe/flexible/wrapper_attributes', array($this, 'wrapper_attributes'), 10, 2); |
| 20 | add_filter('acfe/flexible/layouts/div', array($this, 'layout_div'), 10, 3); |
| 21 | add_filter('acfe/flexible/layouts/placeholder', array($this, 'layout_placeholder'), 10, 3); |
| 22 | add_filter('acfe/flexible/layouts/handle', array($this, 'layout_handle'), 10, 3); |
| 23 | add_filter('acfe/flexible/layouts/icons', array($this, 'layout_icons'), 50, 3); |
| 24 | add_filter('acfe/flexible/action_buttons', array($this, 'action_buttons'), 10, 3); |
| 25 | |
| 26 | } |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * defaults_field |
| 31 | * |
| 32 | * @param $field |
| 33 | * |
| 34 | * @return mixed |
| 35 | */ |
| 36 | function defaults_field($field){ |
| 37 | |
| 38 | $field['acfe_flexible_layouts_state'] = false; |
| 39 | |
| 40 | return $field; |
| 41 | |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * render_field_settings |
| 47 | * |
| 48 | * @param $field |
| 49 | */ |
| 50 | function render_field_settings($field){ |
| 51 | |
| 52 | // Layouts: Force State |
| 53 | acf_render_field_setting($field, array( |
| 54 | 'label' => __('Default Layouts State', 'acfe'), |
| 55 | 'name' => 'acfe_flexible_layouts_state', |
| 56 | 'key' => 'acfe_flexible_layouts_state', |
| 57 | 'instructions' => '<a href="https://www.acf-extended.com/features/fields/flexible-content/advanced-settings#layout-states" target="_blank">' . __('See documentation', 'acfe') . '</a>', |
| 58 | 'type' => 'radio', |
| 59 | 'layout' => 'horizontal', |
| 60 | 'default_value' => 'user', |
| 61 | 'placeholder' => __('Default (User preference)', 'acfe'), |
| 62 | 'choices' => array( |
| 63 | 'user' => __('User preference', 'acfe'), |
| 64 | 'collapse' => __('Collapsed', 'acfe'), |
| 65 | 'open' => __('Opened', 'acfe'), |
| 66 | 'force_open' => __('Always opened', 'acfe'), |
| 67 | ), |
| 68 | 'conditional_logic' => array( |
| 69 | array( |
| 70 | array( |
| 71 | 'field' => 'acfe_flexible_advanced', |
| 72 | 'operator' => '==', |
| 73 | 'value' => '1', |
| 74 | ), |
| 75 | array( |
| 76 | 'field' => 'acfe_flexible_modal_edit_enabled', |
| 77 | 'operator' => '!=', |
| 78 | 'value' => '1', |
| 79 | ) |
| 80 | ) |
| 81 | ) |
| 82 | )); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | * wrapper_attributes |
| 89 | * |
| 90 | * @param $wrapper |
| 91 | * @param $field |
| 92 | * |
| 93 | * @return mixed |
| 94 | */ |
| 95 | function wrapper_attributes($wrapper, $field){ |
| 96 | |
| 97 | // check setting |
| 98 | if(($field['acfe_flexible_layouts_state'] !== 'open' && $field['acfe_flexible_layouts_state'] !== 'force_open') || $field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 99 | return $wrapper; |
| 100 | } |
| 101 | |
| 102 | $wrapper['data-acfe-flexible-open'] = 1; |
| 103 | |
| 104 | return $wrapper; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * layout_div |
| 111 | * |
| 112 | * @param $div |
| 113 | * @param $layout |
| 114 | * @param $field |
| 115 | * |
| 116 | * @return mixed |
| 117 | */ |
| 118 | function layout_div($div, $layout, $field){ |
| 119 | |
| 120 | if($field['acfe_flexible_layouts_state'] !== 'collapse'){ |
| 121 | return $div; |
| 122 | } |
| 123 | |
| 124 | // Already in class |
| 125 | if(in_array('-collapsed', explode(' ', $div['class']))){ |
| 126 | return $div; |
| 127 | } |
| 128 | |
| 129 | $div['class'] .= ' -collapsed'; |
| 130 | |
| 131 | return $div; |
| 132 | |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /** |
| 137 | * layout_placeholder |
| 138 | * |
| 139 | * @param $placeholder |
| 140 | * @param $layout |
| 141 | * @param $field |
| 142 | * |
| 143 | * @return mixed |
| 144 | */ |
| 145 | function layout_placeholder($placeholder, $layout, $field){ |
| 146 | |
| 147 | if($field['acfe_flexible_layouts_state'] === 'collapse' || $field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 148 | return $placeholder; |
| 149 | } |
| 150 | |
| 151 | // Already in class |
| 152 | if(in_array('acf-hidden', explode(' ', $placeholder['class']))){ |
| 153 | return $placeholder; |
| 154 | } |
| 155 | |
| 156 | $placeholder['class'] .= ' acf-hidden'; |
| 157 | |
| 158 | return $placeholder; |
| 159 | |
| 160 | } |
| 161 | |
| 162 | |
| 163 | /** |
| 164 | * layout_handle |
| 165 | * |
| 166 | * @param $handle |
| 167 | * @param $layout |
| 168 | * @param $field |
| 169 | * |
| 170 | * @return mixed |
| 171 | */ |
| 172 | function layout_handle($handle, $layout, $field){ |
| 173 | |
| 174 | if($field['acfe_flexible_layouts_state'] !== 'force_open'){ |
| 175 | return $handle; |
| 176 | } |
| 177 | |
| 178 | // remove [data-name="collapse-layout"] so it doesn't trigger js click event |
| 179 | acfe_unset($handle, 'data-name'); |
| 180 | |
| 181 | return $handle; |
| 182 | |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /** |
| 187 | * layout_icons |
| 188 | * |
| 189 | * @param $icons |
| 190 | * @param $layout |
| 191 | * @param $field |
| 192 | * |
| 193 | * @return mixed |
| 194 | */ |
| 195 | function layout_icons($icons, $layout, $field){ |
| 196 | |
| 197 | if($field['acfe_flexible_layouts_state'] !== 'force_open'){ |
| 198 | return $icons; |
| 199 | } |
| 200 | |
| 201 | acfe_unset($icons, 'collapse'); |
| 202 | |
| 203 | return $icons; |
| 204 | |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /** |
| 209 | * action_buttons |
| 210 | * |
| 211 | * @param $buttons |
| 212 | * @param $field |
| 213 | * @param $position |
| 214 | * |
| 215 | * @return array|mixed |
| 216 | */ |
| 217 | function action_buttons($buttons, $field, $position){ |
| 218 | |
| 219 | // remove expand/collapse top actions |
| 220 | if($position === 'top' && $field['acfe_flexible_layouts_state'] === 'force_open'){ |
| 221 | acfe_unset($buttons, 'expand'); |
| 222 | acfe_unset($buttons, 'collapse'); |
| 223 | } |
| 224 | |
| 225 | return $buttons; |
| 226 | |
| 227 | } |
| 228 | |
| 229 | } |
| 230 | |
| 231 | acf_new_instance('acfe_field_flexible_content_state'); |
| 232 | |
| 233 | endif; |