PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.9.2.7
Advanced Custom Fields: Extended v0.9.2.7
0.9.2.7 0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields / field-flexible-content-hide.php
acf-extended / includes / fields Last commit date
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-hide.php
364 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('acfe_field_flexible_content_hide')):
8
9 class acfe_field_flexible_content_hide{
10
11 /**
12 * construct
13 */
14 function __construct(){
15
16 // Hooks
17 add_filter('acfe/flexible/defaults_field', array($this, 'defaults_field'), 7);
18 add_action('acfe/flexible/render_field_settings', array($this, 'render_field_settings'), 7);
19
20 add_filter('acfe/flexible/validate_field', array($this, 'validate_hide'));
21 add_filter('acfe/flexible/layouts/icons', array($this, 'layout_icons'), 60, 3);
22 add_filter('acfe/flexible/layouts/more_action_buttons', array($this, 'more_action_buttons'), 10, 2);
23 add_filter('acfe/flexible/layout_renamed', array($this, 'layout_renamed'), 20, 3);
24 add_filter('acfe/flexible/layout_disabled', array($this, 'layout_disabled'), 20, 3);
25 add_filter('acfe/flexible/action_buttons', array($this, 'action_buttons'), 10, 3);
26 add_filter('acfe/flexible/action_buttons', array($this, 'action_buttons_late'), 50, 3);
27
28 }
29
30
31 /**
32 * defaults_field
33 *
34 * @param $field
35 *
36 * @return mixed
37 */
38 function defaults_field($field){
39
40 $field['acfe_flexible_remove_button'] = array();
41 $field['acfe_flexible_remove_top_actions'] = array();
42
43 return $field;
44
45 }
46
47
48 /**
49 * validate_hide
50 *
51 * @param $field
52 *
53 * @return mixed
54 */
55 function validate_hide($field){
56
57 $field['acfe_flexible_remove_button'] = acfe_as_array($field['acfe_flexible_remove_button']);
58 $field['acfe_flexible_remove_top_actions'] = acfe_as_array($field['acfe_flexible_remove_top_actions']);
59
60 return $field;
61
62 }
63
64
65 /**
66 * render_field_settings
67 *
68 * @param $field
69 */
70 function render_field_settings($field){
71
72 $hide_choices = array(
73 'add' => __('Hide "Add Row"', 'acfe'),
74 'collapse' => __('Hide "Collapse"', 'acfe'),
75 'delete' => __('Hide "Delete"', 'acfe'),
76 'duplicate' => __('Hide "Duplicate"', 'acfe'),
77 );
78
79 // ACF 6.5+
80 if(acfe_is_acf('6.5')){
81 $hide_choices['rename'] = __('Hide "Rename"', 'acfe');
82 $hide_choices['disable'] = __('Hide "Disable"', 'acfe');
83 $hide_choices['top_actions'] = __('Hide "Top Actions"', 'acfe');
84 }
85
86 // pre ACF-5.9
87 if(!acfe_is_acf('5.9')){
88 acfe_unset($hide_choices, 'duplicate');
89 }
90
91 // Hide Buttons
92 acf_render_field_setting($field, array(
93 'label' => __('Hide Buttons', 'acfe'),
94 'name' => 'acfe_flexible_remove_button',
95 'key' => 'acfe_flexible_remove_button',
96 'instructions' => '<a href="https://www.acf-extended.com/features/fields/flexible-content/advanced-settings#hide-buttons" target="_blank">' . __('See documentation', 'acfe') . '</a>',
97 'type' => 'checkbox',
98 'default_value' => '',
99 'layout' => 'horizontal',
100 'choices' => $hide_choices,
101 'conditional_logic' => array(
102 array(
103 array(
104 'field' => 'acfe_flexible_advanced',
105 'operator' => '==',
106 'value' => '1',
107 ),
108 )
109 )
110 ));
111
112 // ACF 6.5+
113 if(acfe_is_acf('6.5')){
114
115 // Hide Top Actions
116 acf_render_field_setting($field, array(
117 'label' => __('Hide Top Actions', 'acfe'),
118 'name' => 'acfe_flexible_remove_top_actions',
119 'key' => 'acfe_flexible_remove_top_actions',
120 'instructions' => '<a href="https://www.acf-extended.com/features/fields/flexible-content/advanced-settings#hide-top-actions" target="_blank">' . __('See documentation', 'acfe') . '</a>',
121 'type' => 'checkbox',
122 'default_value' => '',
123 'layout' => 'horizontal',
124 'choices' => array(
125 'expand' => __('Hide "Expand All"', 'acfe'),
126 'collapse' => __('Hide "Collapse All"', 'acfe'),
127 'add' => __('Hide "Add Row"', 'acfe'),
128 ),
129 'conditional_logic' => array(
130 array(
131 array(
132 'field' => 'acfe_flexible_advanced',
133 'operator' => '==',
134 'value' => '1',
135 ),
136 array(
137 'field' => 'acfe_flexible_remove_button',
138 'operator' => '!=',
139 'value' => 'top_actions',
140 ),
141 )
142 )
143 ));
144
145 }
146
147 }
148
149
150 /**
151 * layout_icons
152 *
153 * Remove the icons from the layout controls
154 *
155 * @param $icons
156 * @param $layout
157 * @param $field
158 *
159 * @return mixed
160 */
161 function layout_icons($icons, $layout, $field){
162
163 if(in_array('add', $field['acfe_flexible_remove_button'])){
164 acfe_unset($icons, 'add');
165 }
166
167 if(in_array('duplicate', $field['acfe_flexible_remove_button'])){
168 acfe_unset($icons, 'duplicate');
169 }
170
171 if(in_array('delete', $field['acfe_flexible_remove_button'])){
172 acfe_unset($icons, 'delete');
173 }
174
175 if(in_array('collapse', $field['acfe_flexible_remove_button'])){
176 acfe_unset($icons, 'collapse');
177 }
178
179 // get more actions buttons (rename, disable...)
180 $more_actions_buttons = acf_get_instance('acfe_field_flexible_content_popup')->get_popup_actions_buttons($field);
181
182 if(empty($more_actions_buttons)){
183 acfe_unset($icons, 'more');
184 }
185
186 return $icons;
187
188 }
189
190
191 /**
192 * more_action_buttons
193 *
194 * Remove the buttons from the layout more actions popup
195 *
196 * @param $buttons
197 * @param $field
198 *
199 * @return void
200 */
201 function more_action_buttons($buttons, $field){
202
203 if(in_array('rename', $field['acfe_flexible_remove_button'])){
204 acfe_unset($buttons, 'rename');
205 }
206
207 if(in_array('disable', $field['acfe_flexible_remove_button'])){
208 acfe_unset($buttons, 'disable');
209 }
210
211 return $buttons;
212
213 }
214
215
216 /**
217 * layout_renamed
218 *
219 * @param $renamed
220 * @param $field
221 * @param $i
222 *
223 * @return mixed|string
224 */
225 function layout_renamed($renamed, $field, $i){
226
227 // never show renamed layout
228 if(in_array('rename', $field['acfe_flexible_remove_button'])){
229 return '';
230 }
231
232 return $renamed;
233
234 }
235
236
237 /**
238 * layout_disabled
239 *
240 * @param $disabled
241 * @param $field
242 * @param $i
243 *
244 * @return false|mixed
245 */
246 function layout_disabled($disabled, $field, $i){
247
248 // never show disabled layout
249 if(in_array('disable', $field['acfe_flexible_remove_button'])){
250 return false;
251 }
252
253 return $disabled;
254
255 }
256
257
258 /**
259 * action_buttons
260 *
261 * @param $buttons
262 * @param $field
263 * @param $position
264 *
265 * @return array|mixed
266 */
267 function action_buttons($buttons, $field, $position){
268
269 // remove add on both top & bottom
270 if(in_array('add', $field['acfe_flexible_remove_button'])){
271 acfe_unset($buttons, 'add');
272 }
273
274 // remove top actions
275 if($position === 'top' && in_array('top_actions', $field['acfe_flexible_remove_button'])){
276 return array(); // return empty array to hide the whole top actions
277 }
278
279 // remove add on top only
280 if($position === 'top' && in_array('add', $field['acfe_flexible_remove_top_actions'])){
281 acfe_unset($buttons, 'add');
282 }
283
284 if(in_array('expand', $field['acfe_flexible_remove_top_actions'])){
285 acfe_unset($buttons, 'expand');
286 }
287
288 if(in_array('collapse', $field['acfe_flexible_remove_top_actions'])){
289 acfe_unset($buttons, 'collapse');
290 }
291
292 return $buttons;
293
294 }
295
296
297 /**
298 * action_buttons_late
299 *
300 * @param $buttons
301 * @param $field
302 * @param $position
303 *
304 * @return array|mixed
305 */
306 function action_buttons_late($buttons, $field, $position){
307
308 // if separator is first or last, remove it
309 if($this->array_key_first($buttons) === 'separator' || $this->array_key_last($buttons) === 'separator'){
310 acfe_unset($buttons, 'separator');
311 }
312
313 return $buttons;
314
315 }
316
317
318 /**
319 * array_key_first
320 *
321 * @param $array
322 *
323 * @return int|string|null
324 */
325 function array_key_first($array){
326
327 if(!is_array($array) || empty($array)){
328 return null;
329 }
330
331 foreach($array as $k => $v){
332 return $k;
333 }
334
335 return null;
336 }
337
338
339 /**
340 * array_key_last
341 *
342 * @param $array
343 *
344 * @return int|string|null
345 */
346 function array_key_last($array){
347
348 if(!is_array($array) || empty($array)){
349 return null;
350 }
351
352 $last = null;
353 foreach($array as $k => $v){
354 $last = $k;
355 }
356
357 return $last;
358 }
359
360 }
361
362 acf_new_instance('acfe_field_flexible_content_hide');
363
364 endif;