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-title.php
260 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_flexible_content_actions_title')): |
| 8 | |
| 9 | class acfe_field_flexible_content_actions_title{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_filter('acfe/flexible/wrapper_attributes', array($this, 'wrapper_attributes'), 10, 2); |
| 17 | add_filter('acfe/flexible/load_fields', array($this, 'load_fields'), 10, 2); |
| 18 | add_filter('acfe/flexible/prepare_layout', array($this, 'prepare_layout'), 10, 5); |
| 19 | add_filter('acfe/flexible/layouts/div', array($this, 'layout_div'), 10, 6); |
| 20 | |
| 21 | add_filter('acf/fields/flexible_content/layout_title', array($this, 'layout_title'), 5, 4); |
| 22 | add_filter('acf/fields/flexible_content/layout_attrs', array($this, 'layout_attrs'), 5, 4); |
| 23 | |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * wrapper_attributes |
| 28 | * |
| 29 | * acfe/flexible/wrapper_attributes |
| 30 | * |
| 31 | * @param $wrapper |
| 32 | * @param $field |
| 33 | * |
| 34 | * @return mixed |
| 35 | */ |
| 36 | function wrapper_attributes($wrapper, $field){ |
| 37 | |
| 38 | // ACF 6.5+ |
| 39 | if(acfe_is_acf('6.5')){ |
| 40 | return $wrapper; |
| 41 | } |
| 42 | |
| 43 | if(in_array('title', $field['acfe_flexible_add_actions'])){ |
| 44 | $wrapper['data-acfe-flexible-title-edition'] = 1; |
| 45 | } |
| 46 | |
| 47 | return $wrapper; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * load_fields |
| 53 | * |
| 54 | * acfe/flexible/load_fields |
| 55 | * |
| 56 | * @param $fields |
| 57 | * @param $field |
| 58 | * |
| 59 | * @return mixed |
| 60 | */ |
| 61 | function load_fields($fields, $field){ |
| 62 | |
| 63 | // ACF 6.5+ |
| 64 | if(acfe_is_acf('6.5')){ |
| 65 | return $fields; |
| 66 | } |
| 67 | |
| 68 | // check setting |
| 69 | if(!in_array('title', $field['acfe_flexible_add_actions'])){ |
| 70 | return $fields; |
| 71 | } |
| 72 | |
| 73 | // loop layouts |
| 74 | foreach($field['layouts'] as $i => $layout){ |
| 75 | |
| 76 | // Vars |
| 77 | $key = "field_{$layout['key']}_title"; |
| 78 | $name = 'acfe_flexible_layout_title'; |
| 79 | $label = $layout['label']; |
| 80 | |
| 81 | // Add local |
| 82 | acf_add_local_field(array( |
| 83 | 'label' => false, |
| 84 | 'key' => $key, |
| 85 | 'name' => $name, |
| 86 | 'type' => 'text', |
| 87 | 'required' => false, |
| 88 | 'maxlength' => false, |
| 89 | 'default_value' => $label, |
| 90 | 'placeholder' => $label, |
| 91 | 'parent_layout' => $layout['key'], |
| 92 | 'parent' => $field['key'] |
| 93 | )); |
| 94 | |
| 95 | // Add sub field |
| 96 | array_unshift($fields, acf_get_field($key)); |
| 97 | |
| 98 | } |
| 99 | |
| 100 | return $fields; |
| 101 | |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /** |
| 106 | * prepare_layout |
| 107 | * |
| 108 | * acfe/flexible/prepare_layout |
| 109 | * |
| 110 | * @param $layout |
| 111 | * @param $field |
| 112 | * @param $i |
| 113 | * @param $value |
| 114 | * @param $prefix |
| 115 | * |
| 116 | * @return mixed |
| 117 | */ |
| 118 | function prepare_layout($layout, $field, $i, $value, $prefix){ |
| 119 | |
| 120 | // ACF 6.5+ |
| 121 | if(acfe_is_acf('6.5')){ |
| 122 | return $layout; |
| 123 | } |
| 124 | |
| 125 | if(empty($layout['sub_fields'])){ |
| 126 | return $layout; |
| 127 | } |
| 128 | |
| 129 | // check setting |
| 130 | if(!in_array('title', $field['acfe_flexible_add_actions'])){ |
| 131 | return $layout; |
| 132 | } |
| 133 | |
| 134 | // extract title sub field |
| 135 | $sub_field = acfe_extract_sub_field($layout, 'acfe_flexible_layout_title', $value); |
| 136 | |
| 137 | if($sub_field){ |
| 138 | |
| 139 | // update prefix to allow for nested values |
| 140 | $sub_field['prefix'] = $prefix; |
| 141 | $sub_field['class'] = 'acfe-flexible-control-title'; |
| 142 | $sub_field['data-acfe-flexible-control-title-input'] = 1; |
| 143 | |
| 144 | $sub_field = acf_validate_field($sub_field); |
| 145 | $sub_field = acf_prepare_field($sub_field); |
| 146 | |
| 147 | $input_attrs = array(); |
| 148 | foreach(array('type', 'id', 'class', 'name', 'value', 'placeholder', 'maxlength', 'pattern', 'readonly', 'disabled', 'required', 'data-acfe-flexible-control-title-input') as $k){ |
| 149 | |
| 150 | if(isset($sub_field[$k])){ |
| 151 | $input_attrs[$k] = $sub_field[$k]; |
| 152 | } |
| 153 | |
| 154 | } |
| 155 | |
| 156 | // render input |
| 157 | echo acf_get_text_input(acf_filter_attrs($input_attrs)); |
| 158 | |
| 159 | } |
| 160 | |
| 161 | return $layout; |
| 162 | |
| 163 | } |
| 164 | |
| 165 | |
| 166 | /** |
| 167 | * layout_div |
| 168 | * |
| 169 | * @param $div |
| 170 | * @param $layout |
| 171 | * @param $field |
| 172 | * |
| 173 | * @return mixed |
| 174 | */ |
| 175 | function layout_div($div, $layout, $field, $i, $value, $prefix){ |
| 176 | |
| 177 | // ACF 6.5+ |
| 178 | if(acfe_is_acf('6.5')){ |
| 179 | return $div; |
| 180 | } |
| 181 | |
| 182 | // remove data-renamed="0|1" |
| 183 | acfe_unset($div, 'data-renamed'); |
| 184 | |
| 185 | // return |
| 186 | return $div; |
| 187 | |
| 188 | } |
| 189 | |
| 190 | |
| 191 | /** |
| 192 | * layout_title |
| 193 | * |
| 194 | * acf/fields/flexible_content/layout_title |
| 195 | * |
| 196 | * @param $title |
| 197 | * @param $field |
| 198 | * @param $layout |
| 199 | * @param $i |
| 200 | * |
| 201 | * @return mixed |
| 202 | */ |
| 203 | function layout_title($title, $field, $layout, $i){ |
| 204 | |
| 205 | // ACF 6.5+ |
| 206 | if(acfe_is_acf('6.5')){ |
| 207 | return $title; |
| 208 | } |
| 209 | |
| 210 | if(!in_array('title', $field['acfe_flexible_add_actions'])){ |
| 211 | return $title; |
| 212 | } |
| 213 | |
| 214 | // get edited title |
| 215 | $value = get_sub_field('acfe_flexible_layout_title'); |
| 216 | if(!empty($value)){ |
| 217 | $title = wp_unslash($value); |
| 218 | } |
| 219 | |
| 220 | return $title; |
| 221 | |
| 222 | } |
| 223 | |
| 224 | |
| 225 | /** |
| 226 | * layout_attrs |
| 227 | * |
| 228 | * acf/fields/flexible_content/layout_attrs |
| 229 | * |
| 230 | * @param $attrs |
| 231 | * @param $field |
| 232 | * @param $layout |
| 233 | * @param $i |
| 234 | * |
| 235 | * @return mixed |
| 236 | */ |
| 237 | function layout_attrs($attrs, $field, $layout, $i){ |
| 238 | |
| 239 | // ACF 6.5+ |
| 240 | if(acfe_is_acf('6.5')){ |
| 241 | return $attrs; |
| 242 | } |
| 243 | |
| 244 | // check setting |
| 245 | if(!in_array('title', $field['acfe_flexible_add_actions'])){ |
| 246 | return $attrs; |
| 247 | } |
| 248 | |
| 249 | $attrs['class'] .= ' acf-js-tooltip'; |
| 250 | $attrs['title'] = __('Layout', 'acfe') . ': ' . esc_attr(strip_tags($layout['label'])); |
| 251 | |
| 252 | return $attrs; |
| 253 | |
| 254 | } |
| 255 | |
| 256 | } |
| 257 | |
| 258 | acf_new_instance('acfe_field_flexible_content_actions_title'); |
| 259 | |
| 260 | endif; |