PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.7
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.7
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / pagebuilders / elementor / elementor.php
widget-options / includes / pagebuilders / elementor Last commit date
elementor.php 1 year ago render.php 1 year ago
elementor.php
508 lines
1 <?php
2
3 /**
4 * Extends funtionality to Elementor Pagebuilder
5 *
6 *
7 * @copyright Copyright (c) 2017, Jeffrey Carandang
8 * @since 4.3
9 */
10 // Exit if accessed directly
11 if (!defined('ABSPATH')) exit;
12
13 if (!function_exists('widgetopts_elementor_section')) {
14 //Add "Widget Options" section to every Elementor Widgets
15 add_action('elementor/element/after_section_end', 'widgetopts_elementor_section', 5, 3);
16 function widgetopts_elementor_section($element, $section_id, $args)
17 {
18 if (Elementor\Plugin::$instance->editor->is_edit_mode()) {
19 global $widget_options;
20
21 //filter the elements first to avoid conflicts that can cause pagebuilder not to load
22 if (!in_array($element->get_name(), array('global-settings', 'section', 'page-settings', 'oew-blog-grid'))) {
23
24 //create array of section_id to set Widget Options Section to single section to avoid issues
25 $widgetopts_elementor_section_id = apply_filters(
26 'widgetopts_elementor_section_id',
27 array(
28 'section_image',
29 'section_advanced',
30 'section_title',
31 'section_editor',
32 'section_video',
33 'section_button',
34 'section_divider',
35 'section_spacer',
36 'section_map',
37 'section_icon',
38 'section_gallery',
39 'section_image_carousel',
40 'section_icon_list',
41 'section_counter',
42 'section_testimonial',
43 'section_tabs',
44 'section_toggle',
45 'section_social_icon',
46 'section_alert',
47 'section_audio',
48 'section_shortcode',
49 'section_anchor',
50 'section_sidebar',
51 'section_layout',
52 'section_slides',
53 'section_form_fields',
54 'section_list',
55 'section_header',
56 'section_pricing',
57 'section_countdown',
58 'section_buttons_content',
59 'section_blockquote_content',
60 'section_content',
61 'section_login_content',
62 'text_elements',
63 'section_side_a_content',
64 'section_side_b_content',
65 '_section_style'
66 )
67 );
68
69 //filter by the section_ids above
70 if (in_array($section_id, $widgetopts_elementor_section_id)) {
71 $element->start_controls_section(
72 'widgetopts_section',
73 [
74 'tab' => Elementor\Controls_Manager::TAB_ADVANCED,
75 'label' => __('Widget Options', 'widget-options'),
76 ],
77 [
78 'overwrite' => true
79 ]
80 );
81
82 $element->start_controls_tabs('widgetopts_content_tabs', [
83 'overwrite' => true
84 ]);
85
86 if (isset($widget_options['visibility']) && 'activate' == $widget_options['visibility']) {
87 widgetopts_elementor_tab_visibility($element, $section_id, $args);
88 }
89
90 if (isset($widget_options['state']) && 'activate' == $widget_options['state']) {
91 widgetopts_elementor_tab_state($element, $section_id, $args);
92 }
93
94 if (current_user_can('administrator') && ('activate' == $widget_options['logic'] || (isset($widget_options['sliding']) && 'activate' == $widget_options['sliding'] && in_array($element->get_name(), array('button', 'button_plus', 'eael-creative-button', 'cta'))))) {
95 widgetopts_elementor_tab_settings($element, $section_id, $args);
96 }
97
98 //upsell pro
99 if (!is_plugin_active('extended-widget-options/plugin.php')) {
100 $element->start_controls_tab(
101 'widgetopts_tab_upsell',
102 [
103 'label' => __('<i class="dashicons dashicons-plus"></i>', 'widget-options')
104 ],
105 [
106 'overwrite' => true
107 ]
108 );
109 $upgrade_link = apply_filters('widget_options_site_url', trailingslashit(WIDGETOPTS_PLUGIN_WEBSITE) . '?utm_source=elementor&utm_medium=upgrade&utm_campaign=upgradebtn');
110 $element->add_control(
111 'widgetopts_pro',
112 [
113 'type' => Elementor\Controls_Manager::RAW_HTML,
114 'raw' => '<div class="elementor-panel-nerd-box">
115 <i class="elementor-panel-nerd-box-icon dashicons dashicons-lock"></i>
116 <div class="elementor-panel-nerd-box-title">' .
117 __('Unlock All Widget Options', 'widget-options') .
118 '</div>
119 <div class="elementor-panel-nerd-box-message">' .
120 __('Upgrade to Widget Options Extended to unlock all options to easily control and manage each Elementor widget.', 'widget-options') .
121 '</div>
122 <a href="' . $upgrade_link . '" class="elementor-panel-nerd-box-link elementor-button elementor-button-default elementor-go-pro" target="_blank">' .
123 __('Upgrade Now!', 'widget-options') .
124 '</a>
125 </div>',
126 ],
127 [
128 'overwrite' => true
129 ]
130 );
131 $element->end_controls_tab();
132 }
133 $element->end_controls_tabs();
134
135 $element->end_controls_section();
136 }
137 }
138 }
139 }
140 }
141
142 if (!function_exists('widgetopts_elementor_tab_visibility')) {
143 function widgetopts_elementor_tab_visibility($element, $section_id, $args)
144 {
145 global $widget_options, $widgetopts_taxonomies, $widgetopts_pages, $widgetopts_types, $widgetopts_categories;
146
147 $pages = (!empty($widgetopts_pages)) ? $widgetopts_pages : array();
148 $taxonomies = (!empty($widgetopts_taxonomies)) ? $widgetopts_taxonomies : array();
149 $types = (!empty($widgetopts_types)) ? $widgetopts_types : array();
150 $categories = (!empty($widgetopts_categories)) ? $widgetopts_categories : array();
151
152 // print_r( $get_terms['community-category'] );
153
154 $element->start_controls_tab(
155 'widgetopts_tab_visibility',
156 [
157 'label' => __('<span class="dashicons dashicons-visibility"></span>', 'widget-options')
158 ],
159 [
160 'overwrite' => true
161 ]
162 );
163
164 $element->add_control(
165 'widgetopts_visibility',
166 [
167 'label' => __('Show/Hide', 'widget-options'),
168 'type' => Elementor\Controls_Manager::SELECT,
169 'default' => 'hide',
170 'options' => [
171 'show' => __('Show on Selected Pages'),
172 'hide' => __('Hide on Selected Pages')
173 ],
174 // 'separator' => 'none'
175 ],
176 [
177 'overwrite' => true
178 ]
179 );
180
181 if (isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['post_type']) && '1' == $widget_options['settings']['visibility']['post_type']) {
182 $pages_array = array();
183 if (!empty($pages)) {
184 foreach ($pages as $page) {
185 $pages_array[$page->ID] = $page->post_title;
186 }
187
188 $element->add_control(
189 'widgetopts_pages',
190 [
191 'label' => __('Pages', 'widget-options'),
192 'type' => Elementor\Controls_Manager::SELECT2,
193 'multiple' => true,
194 'label_block' => true,
195 'separator' => 'before',
196 'options' => $pages_array,
197 'render_type' => 'none',
198 'description' => __('Click on the field to search and select pages', 'widget-options')
199 ],
200 [
201 'overwrite' => true
202 ]
203 );
204 }
205
206 if (!empty($types)) {
207 $types_array = array();
208 foreach ($types as $ptype => $type) {
209 $types_array[$ptype] = $type->labels->name;
210 }
211
212 $element->add_control(
213 'widgetopts_types',
214 [
215 'label' => __('Post Types', 'widget-options'),
216 'type' => Elementor\Controls_Manager::SELECT2,
217 'multiple' => true,
218 'label_block' => true,
219 'separator' => 'before',
220 'options' => $types_array,
221 'render_type' => 'none',
222 'description' => __('Click on the field to search and select custom post types', 'widget-options')
223 ],
224 [
225 'overwrite' => true
226 ]
227 );
228 }
229 }
230
231 if (isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['taxonomies']) && '1' == $widget_options['settings']['visibility']['taxonomies']) {
232
233 if (!empty($categories)) {
234 $cat_array = array();
235 foreach ($categories as $cat) {
236 $cat_array[$cat->cat_ID] = $cat->cat_name;
237 }
238
239 $element->add_control(
240 'widgetopts_tax_category',
241 [
242 'label' => __('Categories', 'widget-options'),
243 'type' => Elementor\Controls_Manager::SELECT2,
244 'multiple' => true,
245 'label_block' => true,
246 'separator' => 'before',
247 'options' => $cat_array,
248 'render_type' => 'none',
249 'description' => __('Click on the field to search and select categories', 'widget-options')
250 ],
251 [
252 'overwrite' => true
253 ]
254 );
255 }
256
257 if (!empty($taxonomies)) {
258 $tax_array = array();
259 foreach ($taxonomies as $taxonomy) {
260 $tax_array[$taxonomy->name] = $taxonomy->label;
261 }
262
263 $element->add_control(
264 'widgetopts_taxonomies',
265 [
266 'label' => __('Taxonomies', 'widget-options'),
267 'type' => Elementor\Controls_Manager::SELECT2,
268 'multiple' => true,
269 'label_block' => true,
270 'separator' => 'before',
271 'options' => $tax_array,
272 'render_type' => 'none',
273 'description' => __('Click on the field to search and select taxonomies', 'widget-options')
274 ],
275 [
276 'overwrite' => true
277 ]
278 );
279 }
280 }
281
282 if (isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['misc']) && '1' == $widget_options['settings']['visibility']['misc']) {
283 $element->add_control(
284 'widgetopts_misc',
285 [
286 'label' => __('Miscellaneous', 'widget-options'),
287 'type' => Elementor\Controls_Manager::SELECT2,
288 'multiple' => true,
289 'label_block' => true,
290 'separator' => 'before',
291 'options' => [
292 'home' => __('Home/Front', 'widget-options'),
293 'blog' => __('Blog', 'widget-options'),
294 'archives' => __('Archives', 'widget-options'),
295 '404' => __('404', 'widget-options'),
296 'search' => __('Search', 'widget-options')
297 ],
298 'render_type' => 'none',
299 'description' => __('Click on the field to search and select miscellaneous pages', 'widget-options')
300 ],
301 [
302 'overwrite' => true
303 ]
304 );
305 }
306 $element->end_controls_tab();
307 }
308 }
309
310 if (!function_exists('widgetopts_elementor_tab_state')) {
311 function widgetopts_elementor_tab_state($element, $section_id, $args)
312 {
313 global $widget_options;
314
315 $element->start_controls_tab(
316 'widgetopts_tab_state',
317 [
318 'label' => __('<span class="dashicons dashicons-admin-users"></span>', 'widget-options')
319 ],
320 [
321 'overwrite' => true
322 ]
323 );
324
325 $element->add_control(
326 'widgetopts_roles_state',
327 [
328 'label' => __('User Login State', 'widget-options'),
329 'type' => Elementor\Controls_Manager::SELECT,
330 'default' => 'hide',
331 'options' => [
332 '' => __('Select Visibility Option'),
333 'in' => __('Show only for Logged-in Users'),
334 'out' => __('Show only for Logged-out Users')
335 ],
336 'description' => __('Restrict widget visibility for logged-in and logged-out users.', 'widget-options')
337 ],
338 [
339 'overwrite' => true
340 ]
341 );
342
343 $element->end_controls_tab();
344 }
345 }
346
347 if (!function_exists('widgetopts_elementor_tab_settings')) {
348 function widgetopts_elementor_tab_settings($element, $section_id, $args)
349 {
350 global $widget_options;
351
352 $element->start_controls_tab(
353 'widgetopts_tab_settings',
354 [
355 'label' => __('<span class="dashicons dashicons-admin-generic"></span>', 'widget-options')
356 ],
357 [
358 'overwrite' => true
359 ]
360 );
361
362 if (is_plugin_active('sliding-widget-options/plugin.php') && 'activate' == $widget_options['sliding'] && in_array($element->get_name(), array('button', 'button_plus', 'eael-creative-button', 'cta'))) {
363 $element->add_control(
364 'widgetopts_open_sliding',
365 [
366 'label' => __('Open Pop-up or Sliding Widgets', 'widget-options'),
367 'type' => Elementor\Controls_Manager::SWITCHER,
368 'return_value' => 'on',
369 'default' => '',
370 'separator' => 'none'
371 ],
372 [
373 'overwrite' => true
374 ]
375 );
376 }
377
378 if ('activate' == $widget_options['logic'] && current_user_can('administrator')) {
379
380 $element->add_control(
381 'widgetopts_logic',
382 [
383 'type' => Elementor\Controls_Manager::TEXTAREA,
384 'label' => __('Display Widget Logic', 'widget-options'),
385 'description' => __('Add your PHP Conditional Tags. Please note that this will be EVAL\'d directly.', 'widget-options'),
386 // 'separator' => 'none',
387 ],
388 [
389 'overwrite' => true
390 ]
391 );
392 }
393
394
395 if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) {
396 $fields = array();
397
398 if (function_exists('acf_get_field_groups')) {
399 $groups = acf_get_field_groups();
400 if (is_array($groups)) {
401 foreach ($groups as $group) {
402 $fields_group = acf_get_fields($group);
403 if (!empty($fields_group)) {
404 foreach ($fields_group as $k => $fg) {
405 $fields[$fg['key']] = $fg['label'];
406 }
407 }
408 }
409 }
410 } else {
411 $groups = apply_filters('acf/get_field_groups', array());
412 if (is_array($groups)) {
413 foreach ($groups as $group) {
414 $fields_group = apply_filters('acf/field_group/get_fields', array(), $group['id']);
415 if (!empty($fields_group)) {
416 foreach ($fields_group as $k => $fg) {
417 $fields[$fg['key']] = $fg['label'];
418 }
419 }
420 }
421 }
422 }
423
424 $element->add_control(
425 'widgetopts_acf_title',
426 [
427 'type' => Elementor\Controls_Manager::RAW_HTML,
428 'separator' => 'before',
429 'raw' => '<h3>' . __('Advanced Custom Fields', 'widget-options') . '</h3>',
430 ],
431 [
432 'overwrite' => true
433 ]
434 );
435
436 $element->add_control(
437 'widgetopts_acf_visibility',
438 [
439 'label' => __('Show/Hide', 'widget-options'),
440 'type' => Elementor\Controls_Manager::SELECT,
441 'default' => 'hide',
442 'options' => [
443 'show' => __('Show when Condition\'s Met'),
444 'hide' => __('Hide when Condition\'s Met')
445 ],
446 'separator' => 'before',
447 ],
448 [
449 'overwrite' => true
450 ]
451 );
452
453 $element->add_control(
454 'widgetopts_acf_field',
455 [
456 'label' => __('Select ACF Field', 'widget-options'),
457 'type' => Elementor\Controls_Manager::SELECT2,
458 'multiple' => false,
459 'label_block' => true,
460 'options' => $fields,
461 'render_type' => 'none',
462 'description' => __('Select ACF field.', 'widget-options')
463 ],
464 [
465 'overwrite' => true
466 ]
467 );
468
469 $element->add_control(
470 'widgetopts_acf_condition',
471 [
472 'label' => __('Condition', 'widget-options'),
473 'type' => Elementor\Controls_Manager::SELECT2,
474 'multiple' => false,
475 'label_block' => true,
476 'options' => [
477 'equal' => __('Is Equal To', 'widget-options'),
478 'not_equal' => __('Is Not Equal To', 'widget-options'),
479 'contains' => __('Contains', 'widget-options'),
480 'not_contains' => __('Does Not Contain', 'widget-options'),
481 'empty' => __('Is Empty', 'widget-options'),
482 'not_empty' => __('Is Not Empty', 'widget-options')
483 ],
484 'render_type' => 'none',
485 'description' => __('Select your condition for this widget visibility.', 'widget-options')
486 ],
487 [
488 'overwrite' => true
489 ]
490 );
491 $element->add_control(
492 'widgetopts_acf',
493 [
494 'type' => Elementor\Controls_Manager::TEXTAREA,
495 'label' => __('Conditional Value', 'widget-options'),
496 'description' => __('Add your Conditional Value here if you selected Equal to, Not Equal To or Contains on the selection above.', 'widget-options'),
497 // 'separator' => 'none',
498 ],
499 [
500 'overwrite' => true
501 ]
502 );
503 }
504
505 $element->end_controls_tab();
506 }
507 }
508