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 / beaver / beaver.php
widget-options / includes / pagebuilders / beaver Last commit date
beaver.php 1 year ago
beaver.php
854 lines
1 <?php
2
3 /**
4 * Plugin Name: Widget Options for Beaver Builder
5 * Plugin URI: https://widget-options.com/
6 * Description: <strong>Requires <a href="https://wordpress.org/plugins/widget-options/" target="_blank">Widget Options Plugin</a></strong>! Extend functionalities to Beaver Builder for more visibility restriction options.
7 * Version: 1.0
8 * Author: Widget Options Team
9 * Author URI: https://widget-options.com/
10 * Text Domain: widget-options
11 * Domain Path: languages
12 *
13 * @category Widgets
14 * @author Widget Options Team
15 * @version 1.0
16 */
17 // Exit if accessed directly.
18 if (!defined('ABSPATH')) exit;
19 if (!class_exists('WP_Widget_Options_Beaver')) :
20
21 /**
22 * Main WP_Widget_Options_Beaver Class.
23 *
24 * @since 1.0
25 */
26 class WP_Widget_Options_Beaver
27 {
28
29 public static function init()
30 {
31 $class = __CLASS__;
32 new $class;
33 }
34
35 function __construct()
36 {
37 global $widget_options;
38
39 add_filter('fl_builder_register_settings_form', array(&$this, 'widgetopts_beaver_settings'), 10, 2);
40 add_action('fl_builder_control_widgetopts-beaver-tabnav', array(&$this, 'fl_widgetopts_beaver_tabnav'), 1, 4);
41 add_action('wp_enqueue_scripts', array(&$this, 'fl_widgetopts_beaver_scripts'));
42 add_action('fl_builder_control_widgetopts-select2', array(&$this, 'fl_widgetopts_beaver_select2'), 1, 4);
43 add_action('fl_builder_control_widgetopts-upgrade', array(&$this, 'fl_widgetopts_upgrade'), 1, 4);
44 // add_action( 'admin_notices', array( &$this, 'widgetopts_plugin_check' ) );
45
46 add_filter('fl_builder_is_node_visible', array(&$this, 'widgetopts_beaver_is_node_visible'), 10, 2);
47 }
48
49 function widgetopts_beaver_settings($form, $id)
50 {
51 if (!isset($form['widgetopts']) && !is_admin()) {
52 //fix not registering global values
53 if (!function_exists('widgetopts_register_globals')) {
54 require_once WIDGETOPTS_PLUGIN_DIR . 'includes/admin/globals.php';
55 widgetopts_register_globals();
56 }
57
58 global $widget_options, $widgetopts_taxonomies, $widgetopts_types, $widgetopts_categories;
59 $widgetopts_pages = widgetopts_global_pages();
60
61
62 $sections = array();
63 $pages = (!empty($widgetopts_pages)) ? $widgetopts_pages : array();
64 $taxonomies = (!empty($widgetopts_taxonomies)) ? $widgetopts_taxonomies : array();
65 $types = (!empty($widgetopts_types)) ? $widgetopts_types : array();
66 $categories = (!empty($widgetopts_categories)) ? $widgetopts_categories : array();
67
68 $get_terms = array();
69 if (!empty($widget_options['settings']['taxonomies']) && is_array($widget_options['settings']['taxonomies'])) {
70 foreach ($widget_options['settings']['taxonomies'] as $tax_opt => $vall) {
71 $tax_name = 'widgetopts_taxonomy_' . str_replace('-', '__', $tax_opt);
72 // global $$tax_name;
73 if (isset($GLOBALS[$tax_name])) {
74 $get_terms[$tax_opt] = $GLOBALS[$tax_name];
75 }
76 }
77 }
78
79 // print_r( $pages ); die();
80
81 $sections['widgetopts-fields'] = array(
82 'fields' => array(
83 'widgetopts-tabnav' => array(
84 'type' => 'widgetopts-beaver-tabnav',
85 )
86 )
87 );
88
89 if (isset($widget_options['visibility']) && 'activate' == $widget_options['visibility']) {
90 $visibility_fld = array();
91
92 $visibility_fld['widgetopts_visibility_show'] = array(
93 'type' => 'select',
94 'label' => __('Show or Hide', 'widget-options'),
95 'options' => array(
96 'hide' => __('Hide on Selected Pages', 'widget-options'),
97 'show' => __('Show on Selected Pages', 'widget-options')
98 )
99 );
100
101 if (isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['post_type']) && '1' == $widget_options['settings']['visibility']['post_type']) {
102
103 if (!empty($pages)) {
104 $pages_array = array();
105 foreach ($pages as $page) {
106 $pages_array[$page->ID] = $page->post_title;
107 }
108
109 $visibility_fld['widgetopts_visibility_pages'] = array(
110 'type' => 'widgetopts-select2',
111 'label' => __('Pages', 'widget-options'),
112 'options' => $pages_array,
113 'multi-select' => true,
114 'description' => __('Click to search or select', 'widget-options'),
115 );
116 }
117
118 if (!empty($types)) {
119 $types_array = array();
120 foreach ($types as $ptype => $type) {
121 $types_array[$ptype] = $type->labels->name;
122 }
123
124 $visibility_fld['widgetopts_visibility_types'] = array(
125 'type' => 'widgetopts-select2',
126 'label' => __('Post Types', 'widget-options'),
127 'options' => $types_array,
128 'multi-select' => true,
129 'description' => __('Click to search or select', 'widget-options')
130 );
131 }
132 }
133
134 if (isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['taxonomies']) && '1' == $widget_options['settings']['visibility']['taxonomies']) {
135 // if( !empty( $widget_options['settings']['taxonomies'] ) && is_array( $widget_options['settings']['taxonomies'] ) ){
136 // foreach ( $widget_options['settings']['taxonomies'] as $tax_opt => $vallue ) {
137 // $term_array = array();
138 // // if( !empty( $get_terms ) ){
139 // foreach ( $get_terms[ $tax_opt ] as $get_term ) {
140 // $term_array[ $get_term->term_id ] = $get_term->name;
141 // }
142
143 // $visibility_fld['widgetopts_visibility_tax_'. $tax_opt] = array(
144 // 'type' => 'widgetopts-select2',
145 // 'label' => $taxonomies[ $tax_opt ]->label,
146 // 'options' => $term_array,
147 // 'multi-select' => true,
148 // 'description' => __( 'Click to search or select', 'widget-options' )
149 // );
150 // // }
151 // }
152 // }
153
154 if (!empty($categories)) {
155 $cat_array = array();
156 foreach ($categories as $cat) {
157 $cat_array[$cat->cat_ID] = $cat->cat_name;
158 }
159
160 $visibility_fld['widgetopts_visibility_tax_category'] = array(
161 'type' => 'widgetopts-select2',
162 'label' => __('Categories', 'widget-options'),
163 'options' => $cat_array,
164 'multi-select' => true,
165 'description' => __('Click to search or select', 'widget-options')
166 );
167 }
168
169 if (!empty($taxonomies)) {
170 $tax_array = array();
171 foreach ($taxonomies as $taxonomy) {
172 $tax_array[$taxonomy->name] = $taxonomy->label;
173 }
174
175 $visibility_fld['widgetopts_visibility_taxonomies'] = array(
176 'type' => 'widgetopts-select2',
177 'label' => __('Taxonomies', 'widget-options'),
178 'options' => $tax_array,
179 'multi-select' => true,
180 'description' => __('Click to search or select', 'widget-options')
181 );
182 }
183 }
184
185 if (isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['misc']) && '1' == $widget_options['settings']['visibility']['misc']) {
186 $visibility_fld['widgetopts_visibility_misc'] = array(
187 'type' => 'widgetopts-select2',
188 'label' => __('Miscellaneous', 'widget-options'),
189 'options' => array(
190 'home' => __('Home/Front', 'widget-options'),
191 'blog' => __('Blog', 'widget-options'),
192 'archives' => __('Archives', 'widget-options'),
193 '404' => __('404', 'widget-options'),
194 'search' => __('Search', 'widget-options')
195 ),
196 'multi-select' => true,
197 'description' => __('Click to search or select', 'widget-options')
198 );
199 }
200
201 $sections['widgetopts-visibility'] = array(
202 'fields' => $visibility_fld
203 );
204 }
205
206 if (
207 isset($widget_options['logic']) && 'activate' == $widget_options['logic'] ||
208 isset($widget_options['acf']) && 'activate' == $widget_options['acf']
209 ) {
210 $settings_fld = array();
211
212 if (isset($widget_options['logic']) && 'activate' == $widget_options['logic']) {
213 $settings_fld['widgetopts_settings_logic'] = array(
214 'type' => 'textarea',
215 'label' => __('Display Logic', 'widget-options'),
216 'description' => __('<small>PLEASE NOTE that the display logic you introduce is EVAL\'d directly. Anyone who has access to edit widget appearance will have the right to add any code, including malicious and possibly destructive functions. There is an optional filter "widget_options_logic_override" which you can use to bypass the EVAL with your own code if needed.</small>', 'widget-options')
217 );
218 }
219
220 //ACF
221 if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) {
222 $fields = array('' => __('Select Field', 'widget-options'));
223
224 if (function_exists('acf_get_field_groups')) {
225 $groups = acf_get_field_groups();
226 if (is_array($groups)) {
227 foreach ($groups as $group) {
228 $fields_group = acf_get_fields($group);
229 if (!empty($fields_group)) {
230 foreach ($fields_group as $k => $fg) {
231 $fields[$fg['key']] = $fg['label'];
232 }
233 }
234 }
235 }
236 } else {
237 $groups = apply_filters('acf/get_field_groups', array());
238 if (is_array($groups)) {
239 foreach ($groups as $group) {
240 $fields_group = apply_filters('acf/field_group/get_fields', array(), $group['id']);
241 if (!empty($fields_group)) {
242 foreach ($fields_group as $k => $fg) {
243 $fields[$fg['key']] = $fg['label'];
244 }
245 }
246 }
247 }
248 }
249
250 $settings_fld['widgetopts_acf_visibility'] = array(
251 'type' => 'select',
252 'label' => __('Show or Hide based on Advanced Custom Field', 'widget-options'),
253 'options' => array(
254 'hide' => __('Hide when Condition\'s Met', 'widget-options'),
255 'show' => __('Show when Condition\'s Met', 'widget-options')
256 )
257 );
258
259 $settings_fld['widgetopts_acf_field'] = array(
260 'type' => 'select',
261 'label' => __('Select ACF Field', 'widget-options'),
262 'options' => $fields
263 );
264
265 $settings_fld['widgetopts_acf_condition'] = array(
266 'type' => 'select',
267 'label' => __('Select Condition', 'widget-options'),
268 'options' => array(
269 '' => __('Select Condition', 'widget-options'),
270 'equal' => __('Is Equal To', 'widget-options'),
271 'not_equal' => __('Is Not Equal To', 'widget-options'),
272 'contains' => __('Contains', 'widget-options'),
273 'not_contains' => __('Does Not Contain', 'widget-options'),
274 'empty' => __('Is Empty', 'widget-options'),
275 'not_empty' => __('Is Not Empty', 'widget-options')
276 )
277 );
278 $settings_fld['widgetopts_acf_value'] = array(
279 'type' => 'textarea',
280 'label' => __('Conditional Value', 'widget-options'),
281 'description' => __('Add your Conditional Value here if you selected Equal to, Not Equal To or Contains on the selection above.', 'widget-options')
282 );
283 }
284
285 $sections['widgetopts-settings'] = array(
286 'fields' => $settings_fld
287 );
288 }
289
290 $upgrade_fld = array();
291 $upgrade_fld['widgetopts_upgrade_section'] = array(
292 'type' => 'widgetopts-upgrade'
293 );
294
295 $sections['widgetopts-upgrade'] = array(
296 'fields' => $upgrade_fld
297 );
298
299 $form['widgetopts'] = array(
300 'title' => __('Widget Options', 'widget-options'),
301 'sections' => $sections
302 );
303 }
304
305 return $form;
306 }
307
308 function fl_widgetopts_beaver_tabnav($name, $value, $field, $settings)
309 {
310 global $widget_options;
311 ?>
312 <div class="fl-builder-widgetopts-tab">
313 <?php if (isset($widget_options['visibility']) && 'activate' == $widget_options['visibility']) { ?>
314 <a onclick="widgetoptsBeaverModule.navClick(event)" href="#fl-builder-settings-section-widgetopts-visibility" class="widgetopts-s-active"><span class="dashicons dashicons-visibility"></span><?php _e('Visibility', 'widget-options'); ?></a>
315 <?php } ?>
316 <?php if (isset($widget_options['logic']) && 'activate' == $widget_options['logic'] && current_user_can('administrator')) { ?>
317 <a onclick="widgetoptsBeaverModule.navClick(event)" href="#fl-builder-settings-section-widgetopts-settings" class=""><span class="dashicons dashicons-admin-generic"></span><?php _e('Settings', 'widget-options'); ?></a>
318 <?php } ?>
319 <a onclick="widgetoptsBeaverModule.navClick(event)" href="#fl-builder-settings-section-widgetopts-upgrade"><span class="dashicons dashicons-plus"></span><?php _e('More', 'widget-options'); ?></a>
320 </div>
321 <?php }
322
323 function fl_widgetopts_beaver_scripts()
324 {
325 if (class_exists('FLBuilderModel') && FLBuilderModel::is_builder_active()) {
326 $js_dir = WIDGETOPTS_PLUGIN_URL . 'assets/js/';
327 $css_dir = WIDGETOPTS_PLUGIN_URL . 'assets/css/';
328
329 // Use minified libraries if SCRIPT_DEBUG is turned off
330 $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
331
332 wp_enqueue_style('widgetopts-beaver-css', $css_dir . 'beaver-widgetopts.css', array(), WIDGETOPTS_VERSION);
333 wp_enqueue_style('widgetopts-beaver-select2-css', $css_dir . 'select2.min.css', array(), WIDGETOPTS_VERSION);
334 wp_enqueue_style('widgetopts-jquery-ui', $css_dir . '/jqueryui/1.11.4/themes/ui-lightness/jquery-ui.css', array(), WIDGETOPTS_VERSION);
335 wp_enqueue_style('jquery-ui');
336
337 wp_enqueue_script(
338 'beaver-widgetopts',
339 $js_dir . 'jquery.widgetopts.beaver' . $suffix . '.js',
340 array('jquery'),
341 WIDGETOPTS_VERSION,
342 true
343 );
344 wp_enqueue_script(
345 'beaver-widgetopts-select2',
346 $js_dir . 'select2.min.js',
347 array('jquery', 'beaver-widgetopts'),
348 WIDGETOPTS_VERSION,
349 true
350 );
351 wp_enqueue_script(
352 'beaver-widgetopts-s2',
353 $js_dir . 'select2-settings' . $suffix . '.js',
354 array('jquery', 'beaver-widgetopts'),
355 WIDGETOPTS_VERSION,
356 true
357 );
358 }
359 }
360
361 function fl_widgetopts_beaver_get_fld_options($settings, $field, $options = array())
362 {
363 if (!is_object($settings) && !is_array($settings)) return $options;
364
365 foreach ($settings as $key => $val) {
366 if ($key === $field) {
367 if (is_array($val)) {
368 foreach ($val as $v) {
369 $options[$v] = $v;
370 }
371 } else {
372 $options[$val] = $val;
373 }
374 } else {
375 if (is_array($val) || is_object($val)) {
376 $options = $this->fl_widgetopts_beaver_get_fld_options($val, $field, $options);
377 }
378 }
379 }
380
381 return array_unique($options);
382 }
383
384 function fl_widgetopts_beaver_select2($name, $value, $field, $settings)
385 {
386 $options = ($field['options']) ? $field['options'] : array();
387
388 if (isset($field['options_from_field'])) {
389 $options_field = $field['options_from_field'];
390 $post_data = FLBuilderModel::get_post_data();
391 $parent_settings = $post_data['node_settings'];
392
393 $options = $this->fl_widgetopts_beaver_get_fld_options($parent_settings, $options_field, $options);
394 }
395
396 // Create attributes
397 $attributes = '';
398 if (isset($field['attributes']) && is_array($field['attributes'])) {
399 foreach ($field['attributes'] as $key => $val) {
400 $attributes .= $key . '="' . $val . '" ';
401 }
402 }
403
404 if (!empty($options) && $value) {
405 uksort($options, function ($key1, $key2) use ($value) {
406 return array_search($key1, $value) <=> array_search($key2, $value);
407 });
408 }
409 if (!isset($field['class'])) {
410 $field['class'] = '';
411 }
412
413 // Show the select field
414 ?>
415 <select name="<?php echo $name;
416 if (isset($field['multi-select'])) echo '[]'; ?>" class="widgetopts-select2 <?php echo $field['class']; ?>" <?php if (isset($field['multi-select'])) echo 'multiple ';
417 echo $attributes; ?> placeholder="<?php _e('Click to search or select', 'widget-options'); ?>">
418 <option></option>
419 <?php
420 foreach ($options as $option_key => $option_val) :
421
422 if (is_array($option_val) && isset($option_val['premium']) && $option_val['premium'] && true === FL_BUILDER_LITE) {
423 continue;
424 }
425
426 $label = is_array($option_val) ? $option_val['label'] : $option_val;
427
428 if (is_array($value) && in_array($option_key, $value)) {
429 $selected = ' selected="selected"';
430 } else if (!is_array($value) && selected($value, $option_key, true)) {
431 $selected = ' selected="selected"';
432 } else {
433 $selected = '';
434 }
435
436 ?>
437 <option value="<?php echo $option_key; ?>" <?php echo $selected; ?>><?php echo $label; ?></option>
438 <?php endforeach; ?>
439 </select>
440 <?php }
441
442 function fl_widgetopts_upgrade($name, $value, $field, $settings)
443 { ?>
444 <div class="extended-widget-opts-tabcontent extended-widget-opts-tabcontent-gopro">
445 <p class="widgetopts-unlock-features">
446 <span class="dashicons dashicons-lock"></span><?php _e('Unlock all Options', 'widget-options'); ?>
447 </p>
448 <p>
449 <?php _e('Get the world\'s most complete widget management now with Beaver Builder integration! Upgrade to extended version to get:', 'widget-options'); ?>
450 </p>
451 <ul>
452 <li>
453 <span class="dashicons dashicons-lock"></span> <?php _e('Animation Options', 'widget-options'); ?>
454 </li>
455 <li>
456 <span class="dashicons dashicons-lock"></span> <?php _e('Custom Styling Options', 'widget-options'); ?>
457 </li>
458 <li>
459 <span class="dashicons dashicons-lock"></span> <?php _e('Set Alignment per Devices', 'widget-options'); ?>
460 </li>
461 <li>
462 <span class="dashicons dashicons-lock"></span> <?php _e('User Roles Visibility Restriction', 'widget-options'); ?>
463 </li>
464 <li>
465 <span class="dashicons dashicons-lock"></span> <?php _e('Fixed/Sticky Widget Options', 'widget-options'); ?>
466 </li>
467 <li>
468 <span class="dashicons dashicons-lock"></span> <?php _e('Days and Date Range Restriction', 'widget-options'); ?>
469 </li>
470 <li>
471 <span class="dashicons dashicons-lock"></span> <?php _e('Link Module Block Options', 'widget-options'); ?>
472 </li>
473 <li>
474 <span class="dashicons dashicons-lock"></span> <?php _e('Extended Taxonomy and Post Types Support', 'widget-options'); ?>
475 </li>
476 <li>
477 <span class="dashicons dashicons-lock"></span> <?php _e('Target URLs and Wildcard Restrictions', 'widget-options'); ?>
478 </li>
479 <li>
480 <span class="dashicons dashicons-lock"></span> <?php _e('Beaver Builder Support', 'widget-options'); ?>
481 </li>
482 </ul>
483 <p><strong><a href="<?php echo apply_filters('widget_options_site_url', trailingslashit(WIDGETOPTS_PLUGIN_WEBSITE) . '?utm_source=beaverbuilder&utm_medium=learnmore&utm_campaign=widgetoptsprotab'); ?>" class="button-primary" target="_blank"><?php _e('Learn More', 'widget-options'); ?></a></strong></p>
484 </div>
485 <?php }
486
487 function widgetopts_beaver_is_node_visible($is_visible, $node)
488 {
489
490 //return if editing
491 if (class_exists('FLBuilderModel') && FLBuilderModel::is_builder_active()) {
492 return $is_visible;
493 }
494
495 global $widget_options;
496
497 $settings = $node->settings;
498 $hidden = false;
499 $visibility_opts = isset($settings->widgetopts_visibility_show) ? $settings->widgetopts_visibility_show : 'hide';
500
501 $tax_opts = (isset($widget_options['settings']) && isset($widget_options['settings']['taxonomies_keys'])) ? $widget_options['settings']['taxonomies_keys'] : array();
502 $is_misc = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['misc'])) ? true : false;
503 $is_types = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['post_type'])) ? true : false;
504 $is_tax = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['taxonomies'])) ? true : false;
505 $is_inherit = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['inherit'])) ? true : false;
506
507 // echo '<pre>';
508 // print_r( $settings );
509 // echo '</pre>';
510
511 //pages
512 if ($is_misc && ((is_home() && is_front_page()) || is_front_page())) {
513 if (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && in_array('home', $settings->widgetopts_visibility_misc) && $visibility_opts == 'hide') {
514 $hidden = true; //hide if checked on hidden pages
515 } elseif ((!isset($settings->widgetopts_visibility_misc) || (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && !in_array('home', $settings->widgetopts_visibility_misc))) && $visibility_opts == 'show') {
516 $hidden = true; //hide if not checked on visible pages
517 }
518
519 //do return to bypass other conditions
520 $hidden = apply_filters('widgetopts_beaver_visibility_home', $hidden);
521 if ($hidden) {
522 return false;
523 }
524 } elseif ($is_misc && is_home()) {
525 //NOT CHECKED YET
526 if (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && in_array('blog', $settings->widgetopts_visibility_misc) && $visibility_opts == 'hide') {
527 $hidden = true; //hide if checked on hidden pages
528 } elseif ((!isset($settings->widgetopts_visibility_misc) || (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && !in_array('blog', $settings->widgetopts_visibility_misc))) && $visibility_opts == 'show') {
529 $hidden = true; //hide if not checked on visible pages
530 }
531
532 //do return to bypass other conditions
533 $hidden = apply_filters('widgetopts_beaver_visibility_blog', $hidden);
534 if ($hidden) {
535 return false;
536 }
537 } elseif ($is_tax && is_tag()) {
538
539 if (!isset($settings->widgetopts_visibility_taxonomies) || (isset($settings->widgetopts_visibility_taxonomies) && !is_array($settings->widgetopts_visibility_taxonomies))) {
540 $settings->widgetopts_visibility_taxonomies = array();
541 }
542
543 if (in_array('post_tag', $settings->widgetopts_visibility_taxonomies) && $visibility_opts == 'hide') {
544 $hidden = true; //hide to all tags
545 } elseif (in_array('post_tag', $settings->widgetopts_visibility_taxonomies) && $visibility_opts == 'show') {
546 $hidden = false; //hide to all tags
547 }
548 //
549 // //do return to bypass other conditions
550 $hidden = apply_filters('widgetopts_beaver_visibility_tags', $hidden);
551 if ($hidden) {
552 return false;
553 }
554 } elseif ($is_tax && is_tax()) {
555 $term = get_queried_object();
556 //taxonomies page
557 if (!isset($settings->widgetopts_visibility_taxonomies) || (isset($settings->widgetopts_visibility_taxonomies) && !is_array($settings->widgetopts_visibility_taxonomies))) {
558 $settings->widgetopts_visibility_taxonomies = array();
559 }
560 // print_r( $term_lists );
561 if (in_array($term->taxonomy, $settings->widgetopts_visibility_taxonomies) && $visibility_opts == 'hide') {
562 $hidden = true; //hide to all tags
563 } elseif (!in_array($term->taxonomy, $settings->widgetopts_visibility_taxonomies) && $visibility_opts == 'show') {
564 $hidden = true; //hide to all tags
565 }
566
567 //do return to bypass other conditions
568 $hidden = apply_filters('widgetopts_beaver_visibility_taxonomies', $hidden);
569 if ($hidden) {
570 return false;
571 }
572 } elseif ($is_misc && is_archive()) {
573 //archives page
574 if (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && in_array('archives', $settings->widgetopts_visibility_misc) && $visibility_opts == 'hide') {
575 $hidden = true; //hide if checked on hidden pages
576 } elseif ((!isset($settings->widgetopts_visibility_misc) || (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && !in_array('archives', $settings->widgetopts_visibility_misc))) && $visibility_opts == 'show') {
577 $hidden = true; //hide if not checked on visible pages
578 }
579
580 //do return to bypass other conditions
581 $hidden = apply_filters('widgetopts_beaver_visibility_archives', $hidden);
582 if ($hidden) {
583 return false;
584 }
585 } elseif ($is_misc && is_404()) {
586 //404 page
587 if (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && in_array('404', $settings->widgetopts_visibility_misc) && $visibility_opts == 'hide') {
588 $hidden = true; //hide if checked on hidden pages
589 } elseif ((!isset($settings->widgetopts_visibility_misc) || (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && !in_array('404', $settings->widgetopts_visibility_misc))) && $visibility_opts == 'show') {
590 $hidden = true; //hide if not checked on visible pages
591 }
592
593 //do return to bypass other conditions
594 $hidden = apply_filters('widgetopts_beaver_visibility_404', $hidden);
595 if ($hidden) {
596 return false;
597 }
598 } elseif ($is_misc && is_search()) {
599 if (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && in_array('search', $settings->widgetopts_visibility_misc) && $visibility_opts == 'hide') {
600 $hidden = true; //hide if checked on hidden pages
601 } elseif ((!isset($settings->widgetopts_visibility_misc) || (isset($settings->widgetopts_visibility_misc) && is_array($settings->widgetopts_visibility_misc) && !in_array('search', $settings->widgetopts_visibility_misc))) && $visibility_opts == 'show') {
602 $hidden = true;
603 }
604
605 //do return to bypass other conditions
606 $hidden = apply_filters('widgetopts_beaver_visibility_search', $hidden);
607 if ($hidden) {
608 return false;
609 }
610 } elseif (is_single() && !is_page()) {
611 global $wp_query;
612 $post = $wp_query->post;
613
614 if (!isset($settings->widgetopts_visibility_types) || ($is_types && !isset($settings->widgetopts_visibility_types)) || !is_array($settings->widgetopts_visibility_types)) {
615 $settings->widgetopts_visibility_types = array();
616 }
617
618 if ($visibility_opts == 'hide' && in_array($post->post_type, $settings->widgetopts_visibility_types)) {
619 $hidden = true; //hide if exists on hidden pages
620 } elseif ($visibility_opts == 'show' && !in_array($post->post_type, $settings->widgetopts_visibility_types)) {
621 $hidden = true; //hide if doesn't exists on visible pages
622 }
623
624 // do return to bypass other conditions
625 $hidden = apply_filters('widgetopts_beaver_visibility_single', $hidden);
626
627
628 // $taxonomy_names = get_post_taxonomies( $post->ID );
629 // $array_intersect = array_intersect( $tax_opts, $taxonomy_names );
630
631 if (!isset($settings->widgetopts_visibility_tax_category)) {
632 $settings->widgetopts_visibility_tax_category = array();
633 }
634
635 if (isset($settings->widgetopts_visibility_tax_category) && !empty($settings->widgetopts_visibility_tax_category)) {
636 $cats = wp_get_post_categories($post->ID);
637
638 if (is_array($cats) && !empty($cats)) {
639 $checked_cats = $settings->widgetopts_visibility_tax_category;
640 $intersect = array_intersect($cats, $checked_cats);
641 if (!empty($intersect) && $visibility_opts == 'hide') {
642 $hidden = true;
643 } elseif (!empty($intersect) && $visibility_opts == 'show') {
644 $hidden = false;
645 }
646
647 $hidden = apply_filters('widgetopts_beaver_visibility_single_category', $hidden);
648 }
649 }
650
651 if ($hidden) {
652 return false;
653 }
654 } elseif ($is_types && is_page()) {
655 global $wp_query;
656
657 $post = $wp_query->post;
658
659 //do post type condition first
660 if (isset($settings->widgetopts_visibility_types) && is_array($settings->widgetopts_visibility_types) && in_array('page', $settings->widgetopts_visibility_types)) {
661
662 if (!is_array($settings->widgetopts_visibility_types)) {
663 $settings->widgetopts_visibility_types = array();
664 }
665
666 if ($visibility_opts == 'hide' && in_array('page', $settings->widgetopts_visibility_types)) {
667 $hidden = true; //hide if exists on hidden pages
668 } elseif ($visibility_opts == 'show' && !in_array('page', $settings->widgetopts_visibility_types)) {
669 $hidden = true; //hide if doesn't exists on visible pages
670 }
671 } else {
672 // print_r( $settings['widgetopts_pages'] );
673 //do per pages condition
674 if (!isset($settings->widgetopts_visibility_pages) || (isset($settings->widgetopts_visibility_pages) && !is_array($settings->widgetopts_visibility_pages))) {
675 $settings->widgetopts_visibility_pages = array();
676 }
677
678 if ($visibility_opts == 'hide' && in_array($post->ID, $settings->widgetopts_visibility_pages)) {
679 $hidden = true; //hide if exists on hidden pages
680 } elseif ($visibility_opts == 'show' && !in_array($post->ID, $settings->widgetopts_visibility_pages)) {
681 $hidden = true; //hide if doesn't exists on visible pages
682 }
683 }
684
685 // //do return to bypass other conditions
686 $hidden = apply_filters('widgetopts_beaver_visibility_page', $hidden);
687 if ($hidden) {
688 return false;
689 }
690 }
691
692 //ACF
693 if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) {
694 if (isset($settings->widgetopts_acf_field) && !empty($settings->widgetopts_acf_field)) {
695 $acf = get_field_object($settings->widgetopts_acf_field);
696 if ($acf && is_array($acf)) {
697 $acf_visibility = isset($settings->widgetopts_acf_visibility) ? $settings->widgetopts_acf_visibility : 'hide';
698
699 //handle repeater fields
700 if (isset($acf['value'])) {
701 if (is_array($acf['value'])) {
702 $acf['value'] = implode(', ', array_map(function ($acf_array_value) {
703 $acf_implode = '';
704 if (is_array($acf_array_value)) {
705 $acf_implode = implode(',', array_filter($acf_array_value));
706 } else {
707 $acf_implode = $acf_array_value;
708 }
709 return $acf_implode;
710 }, $acf['value']));
711 }
712 }
713
714 switch ($settings->widgetopts_acf_condition) {
715 case 'equal':
716 if (isset($acf['value'])) {
717 if ('show' == $acf_visibility && $acf['value'] == $settings->widgetopts_acf_value) {
718 $hidden = false;
719 } else if ('show' == $acf_visibility && $acf['value'] != $settings->widgetopts_acf_value) {
720 $hidden = true;
721 } else if ('hide' == $acf_visibility && $acf['value'] == $settings->widgetopts_acf_value) {
722 $hidden = true;
723 } else if ('hide' == $acf_visibility && $acf['value'] != $settings->widgetopts_acf_value) {
724 $hidden = false;
725 }
726 }
727 break;
728
729 case 'not_equal':
730 if (isset($acf['value'])) {
731 if ('show' == $acf_visibility && $acf['value'] == $settings->widgetopts_acf_value) {
732 $hidden = true;
733 } else if ('show' == $acf_visibility && $acf['value'] != $settings->widgetopts_acf_value) {
734 $hidden = false;
735 } else if ('hide' == $acf_visibility && $acf['value'] == $settings->widgetopts_acf_value) {
736 $hidden = false;
737 } else if ('hide' == $acf_visibility && $acf['value'] != $settings->widgetopts_acf_value) {
738 $hidden = true;
739 }
740 }
741 break;
742
743 case 'contains':
744 if (isset($acf['value'])) {
745 if ('show' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) !== false) {
746 $hidden = false;
747 } else if ('show' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) === false) {
748 $hidden = true;
749 } else if ('hide' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) !== false) {
750 $hidden = true;
751 } else if ('hide' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) === false) {
752 $hidden = false;
753 }
754 }
755 break;
756
757 case 'not_contains':
758 if (isset($acf['value'])) {
759 if ('show' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) !== false) {
760 $hidden = true;
761 } else if ('show' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) === false) {
762 $hidden = false;
763 } else if ('hide' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) !== false) {
764 $hidden = false;
765 } else if ('hide' == $acf_visibility && strpos($acf['value'], $settings->widgetopts_acf_value) === false) {
766 $hidden = true;
767 }
768 }
769 break;
770
771 case 'empty':
772 if ('show' == $acf_visibility && empty($acf['value'])) {
773 $hidden = false;
774 } else if ('show' == $acf_visibility && !empty($acf['value'])) {
775 $hidden = true;
776 } elseif ('hide' == $acf_visibility && empty($acf['value'])) {
777 $hidden = true;
778 } else if ('hide' == $acf_visibility && !empty($acf['value'])) {
779 $hidden = false;
780 }
781 break;
782
783 case 'not_empty':
784 if ('show' == $acf_visibility && empty($acf['value'])) {
785 $hidden = true;
786 } else if ('show' == $acf_visibility && !empty($acf['value'])) {
787 $hidden = false;
788 } elseif ('hide' == $acf_visibility && empty($acf['value'])) {
789 $hidden = false;
790 } else if ('hide' == $acf_visibility && !empty($acf['value'])) {
791 $hidden = true;
792 }
793 break;
794
795 default:
796 # code...
797 break;
798 }
799
800 // //do return to bypass other conditions
801 $hidden = apply_filters('widgetopts_beaver_visibility_acf', $hidden);
802 if ($hidden) {
803 return false;
804 }
805 }
806 }
807 }
808
809 //widget logic
810 if (isset($widget_options['logic']) && 'activate' == $widget_options['logic']) {
811 if (isset($settings->widgetopts_settings_logic) && !empty($settings->widgetopts_settings_logic)) {
812 //do widget logic
813 $display_logic = stripslashes(trim($settings->widgetopts_settings_logic));
814 $display_logic = apply_filters('widget_options_logic_override', $display_logic);
815 $display_logic = apply_filters('extended_widget_options_logic_override', $display_logic);
816 if ($display_logic === false) {
817 return false;
818 }
819 if ($display_logic === true) {
820 return true;
821 }
822 // if (stristr($display_logic, "return") === false) {
823 // $display_logic = "return (" . $display_logic . ");";
824 // }
825 $display_logic = htmlspecialchars_decode($display_logic, ENT_QUOTES);
826 try {
827 if (!widgetopts_safe_eval($display_logic)) {
828 return false;
829 }
830 } catch (ParseError $e) {
831 return false;
832 }
833 }
834 }
835
836 return $is_visible;
837 }
838 function widgetopts_plugin_check()
839 {
840 if (!defined('WIDGETOPTS_PLUGIN_NAME')) { ?>
841 <div class="widgetopts_activated_notice notice-error notice" style="box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);">
842 <p>
843 <?php _e('<strong>Widget Options Plugin</strong> is required for the <em>Widget Options for Beaver Builder</em> to work properly. Please get the plugin <a href="https://wordpress.org/plugins/widget-options/" target="_blank">here</a>. Thanks!', 'widget-options'); ?>
844 </p>
845 </div>
846 <?php }
847 }
848 }
849
850 add_action('plugins_loaded', array('WP_Widget_Options_Beaver', 'init'));
851 // new WP_Widget_Options_Beaver();
852
853 endif;
854