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