PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 3.7.13
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v3.7.13
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 / widgets / option-tabs / visibility.php
widget-options / includes / widgets / option-tabs Last commit date
alignment.php 4 years ago devices.php 4 years ago settings.php 4 years ago state.php 4 years ago upsell.php 4 years ago visibility.php 4 years ago
visibility.php
357 lines
1 <?php
2 /**
3 * Pages Visibility Widget Options
4 *
5 * @copyright Copyright (c) 2015, Jeffrey Carandang
6 * @since 1.0
7 */
8
9 // Exit if accessed directly
10 if ( ! defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Add Visibility Widget Options Tab
14 *
15 * @since 1.0
16 * @return void
17 */
18
19 /**
20 * Called on 'extended_widget_opts_tabs'
21 * create new tab navigation for visibility options
22 */
23 function widgetopts_tab_visibility( $args ){ ?>
24 <li class="extended-widget-opts-tab-visibility">
25 <a href="#extended-widget-opts-tab-<?php echo $args['id'];?>-visibility" title="<?php _e( 'Visibility', 'widget-options' );?>" ><span class="dashicons dashicons-visibility"></span> <span class="tabtitle"><?php _e( 'Visibility', 'widget-options' );?></span></a>
26 </li>
27 <?php
28 }
29 add_action( 'extended_widget_opts_tabs', 'widgetopts_tab_visibility' );
30
31 /**
32 * Called on 'extended_widget_opts_tabcontent'
33 * create new tab content options for visibility options
34 */
35 function widgetopts_tabcontent_visibility( $args ){
36 global $widget_options, $widgetopts_taxonomies, $widgetopts_pages, $widgetopts_types, $widgetopts_categories;
37
38 $checked = "";
39 $main = "";
40 $selected = 0;
41 $tax_opts = (array) get_option( 'extwopts_taxonomy_settings' );
42 $pages = ( !empty( $widgetopts_pages ) ) ? $widgetopts_pages : array();
43 $taxonomies = ( !empty( $widgetopts_taxonomies ) ) ? $widgetopts_taxonomies : array();
44 $types = ( !empty( $widgetopts_types ) ) ? $widgetopts_types : array();
45 $categories = ( !empty( $widgetopts_categories ) ) ? $widgetopts_categories : array();
46
47 //declare miscellaneous pages - wordpress default pages
48 $misc = array(
49 'home' => __( 'Home/Front', 'widget-options' ),
50 'blog' => __( 'Blog', 'widget-options' ),
51 'archives' => __( 'Archives', 'widget-options' ),
52 // 'single' => __( 'Single Post', 'widget-options' ),
53 '404' => __( '404', 'widget-options' ),
54 'search' => __( 'Search', 'widget-options' )
55 );
56
57 //unset builtin post types
58 foreach ( array( 'revision', 'attachment', 'nav_menu_item' ) as $unset ) {
59 unset( $types[ $unset ] );
60 }
61
62 //pro version only
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_'. $tax_opt;
67 // global $$tax_name;
68 // $get_terms[ $tax_opt ] = $$tax_name;
69 // }
70 // }
71
72
73 //get save values
74 $options_values = '';
75 $misc_values = array();
76 $pages_values = array();
77 $types_values = array();
78 $cat_values = array();
79 $tax_values = array();
80 $terms_values = array();
81 $acf_values = array();
82 if( isset( $args['params'] ) && isset( $args['params']['visibility'] ) ){
83 if( isset( $args['params']['visibility']['options'] ) ){
84 $options_values = $args['params']['visibility']['options'];
85 }
86
87 if( isset( $args['params']['visibility']['misc'] ) ){
88 $misc_values = $args['params']['visibility']['misc'];
89 }
90
91 if( isset( $args['params']['visibility']['pages'] ) ){
92 $pages_values = $args['params']['visibility']['pages'];
93 }
94
95 if( isset( $args['params']['visibility']['types'] ) ){
96 $types_values = $args['params']['visibility']['types'];
97 }
98
99 if( isset( $args['params']['visibility']['categories'] ) ){
100 $cat_values = $args['params']['visibility']['categories'];
101 }
102
103 if( isset( $args['params']['visibility']['taxonomies'] ) ){
104 $tax_values = $args['params']['visibility']['taxonomies'];
105 }
106
107 if( isset( $args['params']['visibility']['tax_terms'] ) ){
108 $terms_values = $args['params']['visibility']['tax_terms'];
109 }
110
111 if( isset( $args['params']['visibility']['acf'] ) ){
112 $acf_values = $args['params']['visibility']['acf'];
113 }
114
115 if( isset( $args['params']['visibility']['selected'] ) ){
116 $selected = $args['params']['visibility']['selected'];
117 }
118
119 if( isset( $args['params']['visibility']['main'] ) ){
120 $main = $args['params']['visibility']['main'];
121 }
122 }
123
124 ?>
125 <div id="extended-widget-opts-tab-<?php echo $args['id'];?>-visibility" class="extended-widget-opts-tabcontent extended-widget-opts-inside-tabcontent extended-widget-opts-tabcontent-visibility">
126 <div class="extended-widget-opts-visibility-m-tabs extended-widget-opts-inside-tabs">
127 <input type="hidden" id="extended-widget-opts-visibility-m-selectedtab" value="<?php echo $main;?>" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][main]" />
128
129 <ul class="extended-widget-opts-visibility-m-tabnav-ul">
130 <li class="extended-widget-opts-visibility-tab-main">
131 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-main" title="<?php _e( 'Home, Blog, Search, etc..', 'widget-options' );?>" ><?php _e( 'WordPress Pages', 'widget-options' );?></a>
132 </li>
133 <?php if( isset( $widget_options['acf'] ) && 'activate' == $widget_options['acf'] ):?>
134 <li class="extended-widget-opts-visibility-tab-main">
135 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-acf" title="<?php _e( 'Advanced Custom Fields', 'widget-options' );?>" ><?php _e( 'ACF', 'widget-options' );?></a>
136 </li>
137 <?php endif;?>
138 </ul>
139
140 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-main" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent">
141 <p><strong><?php _e( 'Hide/Show', 'widget-options' );?></strong>
142 <select class="widefat" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][options]">
143 <option value="hide" <?php if( $options_values == 'hide' ){ echo 'selected="selected"'; }?> ><?php _e( 'Hide on checked pages', 'widget-options' );?></option>
144 <option value="show" <?php if( $options_values == 'show' ){ echo 'selected="selected"'; }?>><?php _e( 'Show on checked pages', 'widget-options' );?></option>
145 </select>
146 </p>
147
148 <div class="extended-widget-opts-visibility-tabs extended-widget-opts-inside-tabs">
149 <input type="hidden" id="extended-widget-opts-visibility-selectedtab" value="<?php echo $selected;?>" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][selected]" />
150 <!-- start tab nav -->
151 <ul class="extended-widget-opts-visibility-tabnav-ul">
152 <?php if( isset( $widget_options['settings']['visibility'] ) &&
153 isset( $widget_options['settings']['visibility']['misc'] ) &&
154 '1' == $widget_options['settings']['visibility']['misc'] ){ ?>
155 <li class="extended-widget-opts-visibility-tab-visibility">
156 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-misc" title="<?php _e( 'Home, Blog, Search, etc..', 'widget-options' );?>" ><?php _e( 'Misc', 'widget-options' );?></a>
157 </li>
158 <?php } ?>
159
160 <?php if( isset( $widget_options['settings']['visibility'] ) &&
161 isset( $widget_options['settings']['visibility']['post_type'] ) &&
162 '1' == $widget_options['settings']['visibility']['post_type'] ){ ?>
163 <li class="extended-widget-opts-visibility-tab-visibility">
164 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-types" title="<?php _e( 'Pages & Custom Post Types', 'widget-options' );?>" ><?php _e( 'Post Types', 'widget-options' );?></a>
165 </li>
166 <?php } ?>
167
168 <?php if( isset( $widget_options['settings']['visibility'] ) &&
169 isset( $widget_options['settings']['visibility']['taxonomies'] ) &&
170 '1' == $widget_options['settings']['visibility']['taxonomies'] ){ ?>
171 <li class="extended-widget-opts-visibility-tab-visibility">
172 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-tax" title="<?php _e( 'Categories, Tags & Taxonomies', 'widget-options' );?>" ><?php _e( 'Taxonomies', 'widget-options' );?></a>
173 </li>
174 <?php } ?>
175 <div class="extended-widget-opts-clearfix"></div>
176 </ul><!-- end tab nav -->
177 <div class="extended-widget-opts-clearfix"></div>
178
179 <?php if( isset( $widget_options['settings']['visibility'] ) &&
180 isset( $widget_options['settings']['visibility']['misc'] ) &&
181 '1' == $widget_options['settings']['visibility']['misc'] ){ ?>
182 <!-- start misc tab content -->
183 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-misc" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent">
184 <div class="extended-widget-opts-misc">
185 <?php foreach ($misc as $key => $value) {
186 if( isset( $misc_values[ $key ] ) && $misc_values[ $key ] == '1' ){
187 $checked = 'checked="checked"';
188 }else{
189 $checked = '';
190 }
191 ?>
192 <p>
193 <input type="checkbox" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][misc][<?php echo $key;?>]" id="<?php echo $args['id'];?>-opts-misc-<?php echo $key;?>" value="1" <?php echo $checked;?> />
194 <label for="<?php echo $args['id'];?>-opts-misc-<?php echo $key;?>"><?php echo $value;?></label>
195 </p>
196 <?php } ?>
197 </div>
198 </div><!-- end misc tab content -->
199 <?php } ?>
200
201 <?php if( isset( $widget_options['settings']['visibility'] ) &&
202 isset( $widget_options['settings']['visibility']['post_type'] ) &&
203 '1' == $widget_options['settings']['visibility']['post_type'] ){ ?>
204 <!-- start types tab content -->
205 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-types" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent">
206 <div class="extended-widget-opts-inner-lists" style="height: 230px;padding: 5px;overflow:auto;">
207 <h4 id="extended-widget-opts-pages"><?php _e( 'Pages', 'widget-options' );?> +/-</h4>
208 <div class="extended-widget-opts-pages">
209 <?php
210 $page_class = new WidgetOpts_Pages_Checkboxes();
211 $page_checkboxes = $page_class->walk( $widgetopts_pages, 0, $args );
212 if ( $page_checkboxes ) {
213 echo '<div class="widgetopts-ul-pages">' . $page_checkboxes . '</div>';
214 }
215 ?>
216 </div>
217
218 <h4 id="extended-widget-opts-types"><?php _e( 'Custom Post Types', 'widget-options' );?> +/-</h4>
219 <div class="extended-widget-opts-types">
220 <?php foreach ($types as $ptype => $type) {
221 // if ( ! $type->has_archive ) {
222 // // don't give the option if there is no archive page
223 // continue;
224 // }
225
226 if( isset( $types_values[ $ptype ] ) && $types_values[ $ptype ] == '1' ){
227 $checked = 'checked="checked"';
228 }else{
229 $checked = '';
230 }
231 ?>
232 <p>
233 <input type="checkbox" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][types][<?php echo $ptype;?>]" id="<?php echo $args['id'];?>-opts-types-<?php echo $ptype;?>" value="1" <?php echo $checked;?> />
234 <label for="<?php echo $args['id'];?>-opts-types-<?php echo $ptype;?>"><?php echo stripslashes( $type->labels->name );?></label>
235 </p>
236 <?php } ?>
237 </div>
238 </div>
239 </div><!-- end types tab content -->
240 <?php } ?>
241
242 <?php if( isset( $widget_options['settings']['visibility'] ) &&
243 isset( $widget_options['settings']['visibility']['taxonomies'] ) &&
244 '1' == $widget_options['settings']['visibility']['taxonomies'] ){ ?>
245 <!-- start tax tab content -->
246 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-tax" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent">
247 <div class="extended-widget-opts-inner-lists" style="height: 230px;padding: 5px;overflow:auto;">
248 <h4 id="extended-widget-opts-categories"><?php _e( 'Categories', 'widget-options' );?> +/-</h4>
249 <div class="extended-widget-opts-categories">
250 <p>
251 <input type="checkbox" name="extended_widget_opts-<?php echo $args['id'];?>[extended_widget_opts][visibility][categories][all_categories]" id="<?php echo $args['id'];?>-opts-categories-all" value="1" <?php if( isset( $cat_values['all_categories'] ) ){ echo 'checked="checked"'; };?> />
252 <label for="<?php echo $args['id'];?>-opts-categories-all"><?php _e( 'All Categories', 'widget-options' );?></label>
253 </p>
254 <?php foreach ($categories as $cat) {
255 if( isset( $cat_values[ $cat->cat_ID ] ) && $cat_values[ $cat->cat_ID ] == '1' ){
256 $checked = 'checked="checked"';
257 }else{
258 $checked = '';
259 }
260 ?>
261 <p>
262 <input type="checkbox" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][categories][<?php echo $cat->cat_ID;?>]" id="<?php echo $args['id'];?>-opts-categories-<?php echo $cat->cat_ID;?>" value="1" <?php echo $checked;?> />
263 <label for="<?php echo $args['id'];?>-opts-categories-<?php echo $cat->cat_ID;?>"><?php echo $cat->cat_name;?></label>
264 </p>
265 <?php } ?>
266 </div>
267
268 <h4 id="extended-widget-opts-taxonomies"><?php _e( 'Taxonomies', 'widget-options' );?> +/-</h4>
269 <div class="extended-widget-opts-taxonomies">
270 <?php foreach ( $taxonomies as $taxonomy ) {
271 if( isset( $tax_values[ $taxonomy->name ] ) && $tax_values[ $taxonomy->name ] == '1' ){
272 $checked = 'checked="checked"';
273 }else{
274 $checked = '';
275 }
276 ?>
277 <p>
278 <input type="checkbox" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][taxonomies][<?php echo $taxonomy->name;?>]" id="<?php echo $args['id'];?>-opts-taxonomies-<?php echo $taxonomy->name;?>" value="1" <?php echo $checked;?> />
279 <label for="<?php echo $args['id'];?>-opts-taxonomies-<?php echo $taxonomy->name;?>"><?php echo $taxonomy->label;?></label> <?php if( isset( $taxonomy->object_type ) && isset( $taxonomy->object_type[0] ) ){ echo ' <small>- '. $taxonomy->object_type[0] .'</small>'; } ?>
280 </p>
281 <?php } ?>
282 </div>
283 </div>
284 </div><!-- end tax tab content -->
285 <?php } ?>
286 </div><!-- end .extended-widget-opts-visibility-tabs -->
287 </div><!-- End WordPress Pages tab -->
288
289 <?php if( isset( $widget_options['acf'] ) && 'activate' == $widget_options['acf'] ):?>
290 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id'];?>-acf" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent">
291 <?php
292 $fields = array();
293
294 if ( function_exists( 'acf_get_field_groups' ) ) {
295 $groups = acf_get_field_groups();
296 if ( is_array( $groups ) ) {
297 foreach ( $groups as $group ) {
298 $fields[ $group['ID'] ] = array( 'title' => $group['title'], 'fields' => acf_get_fields( $group ) );
299 }
300 }
301 }else{
302 $groups = apply_filters( 'acf/get_field_groups', array() );
303 if ( is_array( $groups ) ) {
304 foreach ( $groups as $group ) {
305 $fields[ $group['id'] ] = array( 'title' => $group['title'], 'fields' => apply_filters( 'acf/field_group/get_fields', array(), $group['id'] ) );
306 }
307 }
308 }
309 ?>
310 <p><strong><?php _e( 'Hide/Show', 'widget-options' );?></strong>
311 <select class="widefat" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][acf][visibility]">
312 <option value="hide" <?php echo ( isset( $acf_values['visibility'] ) && $acf_values['visibility'] == 'hide' ) ? 'selected="selected"' : ''?> ><?php _e( 'Hide when Condition\'s met', 'widget-options' );?></option>
313 <option value="show" <?php echo ( isset( $acf_values['visibility'] ) && $acf_values['visibility'] == 'show' ) ? 'selected="selected"' : ''?>><?php _e( 'Show when Condition\'s met', 'widget-options' );?></option>
314 </select>
315 </p>
316
317 <p><strong><?php _e( 'Choose ACF Field', 'widget-options' );?></strong>
318 <select class="widefat" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][acf][field]">
319 <option value=""><?php _e( 'Select Field', 'widget-options' );?></option>
320 <?php
321 if( !empty( $fields ) ){
322 foreach( $fields as $k => $field ){?>
323 <optgroup label="<?php echo $field['title'];?>">
324 <?php foreach( $field['fields'] as $key => $f ){ ?>
325 <option value="<?php echo $f['key'];?>" <?php echo ( isset( $acf_values['field'] ) && $acf_values['field'] == $f['key'] ) ? 'selected="selected"' : ''?> ><?php echo $f['label'];?></option>
326 <?php } ?>
327 </optgroup>
328 <?php }
329 } ?>
330 </select>
331 </p>
332 <p><strong><?php _e( 'Condition', 'widget-options' );?></strong>
333 <select class="widefat" name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][acf][condition]">
334 <option value=""><?php _e( 'Select Condition', 'widget-options' );?></option>
335 <optgroup label="<?php _e( 'Conditional', 'widget-options' );?>">
336 <option value="equal" <?php echo ( isset( $acf_values['condition'] ) && $acf_values['condition'] == 'equal' ) ? 'selected="selected"' : ''?> ><?php _e( 'Is Equal to', 'widget-options' );?></option>
337 <option value="not_equal" <?php echo ( isset( $acf_values['condition'] ) && $acf_values['condition'] == 'not_equal' ) ? 'selected="selected"' : ''?> ><?php _e( 'Is Not Equal to', 'widget-options' );?></option>
338 <option value="contains" <?php echo ( isset( $acf_values['condition'] ) && $acf_values['condition'] == 'contains' ) ? 'selected="selected"' : ''?> ><?php _e( 'Contains', 'widget-options' );?></option>
339 <option value="not_contains" <?php echo ( isset( $acf_values['condition'] ) && $acf_values['condition'] == 'not_contains' ) ? 'selected="selected"' : ''?> ><?php _e( 'Does Not Contain', 'widget-options' );?></option>
340 </optgroup>
341 <optgroup label="<?php _e( 'Value Based', 'widget-options' );?>">
342 <option value="empty" <?php echo ( isset( $acf_values['condition'] ) && $acf_values['condition'] == 'empty' ) ? 'selected="selected"' : ''?> ><?php _e( 'Is Empty', 'widget-options' );?></option>
343 <option value="not_empty" <?php echo ( isset( $acf_values['condition'] ) && $acf_values['condition'] == 'not_empty' ) ? 'selected="selected"' : ''?> ><?php _e( 'Is Not Empty', 'widget-options' );?></option>
344 </optgroup>
345 </select>
346 </p>
347 <p><strong><?php _e( 'Conditional Value', 'widget-options' );?></strong>
348 <textarea name="<?php echo $args['namespace'];?>[extended_widget_opts][visibility][acf][value]" id="<?php echo $args['id'];?>-opts-acf-value" class="widefat widgetopts-acf-conditional"><?php echo (isset( $acf_values['value'] )) ? $acf_values['value'] : ''?></textarea>
349 </p>
350 </div><?php endif; ?>
351 </div><!-- end main tab -->
352
353 </div>
354 <?php
355 }
356 add_action( 'extended_widget_opts_tabcontent', 'widgetopts_tabcontent_visibility'); ?>
357