PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.5
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.5
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 2 years ago animation.php 2 years ago behavior.php 2 years ago days-dates.php 2 years ago devices.php 2 years ago settings.php 2 years ago state.php 2 years ago styling.php 2 years ago upsell.php 2 years ago visibility.php 2 years ago
visibility.php
460 lines
1 <?php
2
3 /**
4 * Pages Visibility Widget Options
5 *
6 * @copyright Copyright (c) 2015, Jeffrey Carandang
7 * @since 1.0
8 */
9
10 // Exit if accessed directly
11 if (!defined('ABSPATH')) exit;
12
13 /**
14 * Add Visibility Widget Options Tab
15 *
16 * @since 1.0
17 * @return void
18 */
19
20 /**
21 * Called on 'extended_widget_opts_tabs'
22 * create new tab navigation for visibility options
23 */
24 function widgetopts_tab_visibility($args)
25 { ?>
26 <li class="extended-widget-opts-tab-visibility">
27 <a href="#extended-widget-opts-tab-<?php echo $args['id']; ?>-visibility" title="<?php _e('Page Visibility', 'widget-options'); ?>"><span class="dashicons dashicons-visibility"></span> <span class="tabtitle"><?php _e('Page Visibility', 'widget-options'); ?></span></a>
28 </li>
29 <?php
30 }
31 add_action('extended_widget_opts_tabs', 'widgetopts_tab_visibility', 1);
32
33 /**
34 * Called on 'extended_widget_opts_tabcontent'
35 * create new tab content options for visibility options
36 */
37 function widgetopts_tabcontent_visibility($args)
38 {
39 global $widget_options, $widgetopts_taxonomies, $widgetopts_pages, $widgetopts_types, $widgetopts_categories;
40
41 $checked = "";
42 $main = "";
43 $selected = 0;
44 $tax_opts = (array) get_option('extwopts_taxonomy_settings');
45 $pages = (!empty($widgetopts_pages)) ? $widgetopts_pages : array();
46 $taxonomies = (!empty($widgetopts_taxonomies)) ? $widgetopts_taxonomies : array();
47 $types = (!empty($widgetopts_types)) ? $widgetopts_types : array();
48 $categories = (!empty($widgetopts_categories)) ? $widgetopts_categories : array();
49
50 //declare miscellaneous pages - wordpress default pages
51 $misc = array(
52 'home' => __('Home/Front', 'widget-options'),
53 'blog' => __('Blog', 'widget-options'),
54 'archives' => __('Archives', 'widget-options'),
55 // 'single' => __( 'Single Post', 'widget-options' ),
56 '404' => __('404', 'widget-options'),
57 'search' => __('Search', 'widget-options')
58 );
59
60 //unset builtin post types
61 foreach (array('revision', 'attachment', 'nav_menu_item') as $unset) {
62 unset($types[$unset]);
63 }
64
65 //pro version only
66 // $get_terms = array();
67 // if( !empty( $widget_options['settings']['taxonomies'] ) && is_array( $widget_options['settings']['taxonomies'] ) ){
68 // foreach ( $widget_options['settings']['taxonomies'] as $tax_opt => $vall ) {
69 // $tax_name = 'widgetopts_taxonomy_'. $tax_opt;
70 // global $$tax_name;
71 // $get_terms[ $tax_opt ] = $$tax_name;
72 // }
73 // }
74
75
76 //get save values
77 $options_values = '';
78 $misc_values = array();
79 $pages_values = array();
80 $types_values = array();
81 $cat_values = array();
82 $tax_values = array();
83 $terms_values = array();
84 $acf_values = array();
85 if (isset($args['params']) && isset($args['params']['visibility'])) {
86
87 if (isset($args['params']['visibility']['options'])) {
88 $options_values = $args['params']['visibility']['options'];
89 }
90
91 if (isset($args['params']['visibility']['misc'])) {
92 $misc_values = $args['params']['visibility']['misc'];
93 }
94
95 if (isset($args['params']['visibility']['pages'])) {
96 $pages_values = $args['params']['visibility']['pages'];
97 }
98
99 if (isset($args['params']['visibility']['types'])) {
100 $types_values = $args['params']['visibility']['types'];
101 }
102
103 if (isset($args['params']['visibility']['categories'])) {
104 $cat_values = $args['params']['visibility']['categories'];
105 }
106
107 if (isset($args['params']['visibility']['taxonomies'])) {
108 $tax_values = $args['params']['visibility']['taxonomies'];
109 }
110
111 if (isset($args['params']['visibility']['tax_terms']) && isset($args['params']['visibility']['tax_terms']['category'])) {
112 //$terms_values = $args['params']['visibility']['tax_terms']['category'];
113 $cat_values = $args['params']['visibility']['tax_terms']['category'];
114 }
115
116 if (isset($args['params']['visibility']['acf'])) {
117 $acf_values = $args['params']['visibility']['acf'];
118 }
119
120 if (isset($args['params']['visibility']['selected'])) {
121 $selected = $args['params']['visibility']['selected'];
122 }
123
124 if (isset($args['params']['visibility']['main'])) {
125 $main = $args['params']['visibility']['main'];
126 }
127 }
128
129 // fix values for older settings
130 $tmpPages_values = array();
131 foreach ($pages_values as $objKey => $objPage) {
132 if (isset($pages_values[$objKey]) && $pages_values[$objKey] == '1') {
133 $tmpPages_values[] = $objKey;
134 } else {
135 $tmpPages_values[] = $objPage;
136 }
137 }
138 $pages_values = $tmpPages_values;
139
140 // fix values for older settings
141 $tmpTerms_values = array();
142 foreach ($cat_values as $objKey => $objTerm) {
143 if (isset($cat_values[$objKey]) && $cat_values[$objKey] == '1') {
144 $_objKey = $objKey;
145 if (is_numeric($objKey)) {
146 if (intval($objKey) == 0) {
147 $_objKey = 1;
148 }
149 }
150
151 $tmpTerms_values[] = $_objKey;
152 } else {
153 $_objTerm = $objTerm;
154 if (is_numeric($objTerm)) {
155 if (intval($objTerm) == 0) {
156 $_objTerm = 1;
157 }
158 }
159
160 $tmpTerms_values[] = $_objTerm;
161 }
162 }
163 $term_values = $tmpTerms_values;
164 ?>
165 <div id="extended-widget-opts-tab-<?php echo $args['id']; ?>-visibility" class="extended-widget-opts-tabcontent extended-widget-opts-tabcontent-visibility">
166
167 <div class="extended-widget-opts-styling-tabs extended-widget-opts-inside-tabs">
168 <input type="hidden" id="extended-widget-opts-visibility-m-selectedtab" value="<?php echo $main; ?>" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][main]" />
169
170
171 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-main" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inside-tabcontent extended-widget-opts-inner-tabcontent">
172 <p><strong><?php _e('Hide/Show', 'widget-options'); ?></strong>
173 <select class="widefat" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][options]">
174 <option value="hide" <?php if ($options_values == 'hide') {
175 echo 'selected="selected"';
176 } ?>><?php _e('Hide on checked pages', 'widget-options'); ?></option>
177 <option value="show" <?php if ($options_values == 'show') {
178 echo 'selected="selected"';
179 } ?>><?php _e('Show on checked pages', 'widget-options'); ?></option>
180 </select>
181 </p>
182
183 <div class="extended-widget-opts-visibility-tabs extended-widget-opts-inside-tabs">
184 <input type="hidden" id="extended-widget-opts-visibility-selectedtab" value="<?php echo $selected; ?>" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][selected]" />
185 <!-- start tab nav -->
186 <ul class="extended-widget-opts-visibility-tabnav-ul">
187 <?php if (
188 isset($widget_options['settings']['visibility']) &&
189 isset($widget_options['settings']['visibility']['misc']) &&
190 '1' == $widget_options['settings']['visibility']['misc']
191 ) { ?>
192 <li class="extended-widget-opts-visibility-tab-visibility">
193 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-misc" title="<?php _e('Pages', 'widget-options'); ?>"><span class="dashicons dashicons-admin-page"></span> <span class="tabtitle"><?php _e('Pages', 'widget-options'); ?></span></a>
194 </li>
195 <?php } ?>
196
197 <?php if (
198 isset($widget_options['settings']['visibility']) &&
199 isset($widget_options['settings']['visibility']['post_type']) &&
200 '1' == $widget_options['settings']['visibility']['post_type']
201 ) { ?>
202 <li class="extended-widget-opts-visibility-tab-visibility">
203 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-types" title="<?php _e('Post Types', 'widget-options'); ?>"><span class="dashicons dashicons-admin-post"></span> <span class="tabtitle"><?php _e('Post Types', 'widget-options'); ?></span></a>
204 </li>
205 <?php } ?>
206
207 <?php if (
208 isset($widget_options['settings']['visibility']) &&
209 isset($widget_options['settings']['visibility']['taxonomies']) &&
210 '1' == $widget_options['settings']['visibility']['taxonomies']
211 ) { ?>
212 <li class="extended-widget-opts-visibility-tab-visibility">
213 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-tax" title="<?php _e('Taxonomies', 'widget-options'); ?>"><span class="dashicons dashicons-rest-api"></span> <span class="tabtitle"><?php _e('Taxonomies', 'widget-options'); ?></span></a>
214 </li>
215 <?php } ?>
216 <div class="extended-widget-opts-clearfix"></div>
217 </ul><!-- end tab nav -->
218 <div class="extended-widget-opts-clearfix"></div>
219
220 <?php if (
221 isset($widget_options['settings']['visibility']) &&
222 isset($widget_options['settings']['visibility']['misc']) &&
223 '1' == $widget_options['settings']['visibility']['misc']
224 ) { ?>
225 <!-- start misc tab content -->
226 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-misc" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent">
227 <div class="extended-widget-opts-misc extended-widget-opts-inner-lists" style="padding-top: 10px;">
228 <p class="widgetopts-subtitle">Default Pages</p>
229 <?php foreach ($misc as $key => $value) {
230 if (isset($misc_values[$key]) && $misc_values[$key] == '1') {
231 $checked = 'checked="checked"';
232 } else {
233 $checked = '';
234 }
235 ?>
236 <p>
237 <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; ?> />
238 <label for="<?php echo $args['id']; ?>-opts-misc-<?php echo $key; ?>"><?php echo $value; ?></label>
239 </p>
240 <?php } ?>
241
242 <h4 class="widgetopts-subtitle" id="extended-widget-opts-pages"><?php _e('Pages', 'widget-options'); ?> +/-<br>
243 <small>Type atleast 3 characters to initiate the search</small>
244 </h4>
245 <div class="extended-widget-opts-pages extended-widget-opts-parent-option">
246
247 <div style="margin-bottom: 10px;">
248 <button type="button" class="widgetopts-search-option-btn" style="width: 75px; background-color: #3D434A; color: #fff; border-radius: 10px 0px 0 10px; border: 1.5px solid #3D434A;">Search</button>
249 <button type="button" class="widgetopts-dropdown-option-btn" style="margin-left: -5px;width: 75px;border-radius: 0 10px 10px 0;color: #777A80;background-color: #fff;border: 1.5px solid #777A80;">Checkbox</button>
250 </div>
251
252 <select class="widefat extended-widget-opts-select2-dropdown extended-widget-opts-select2-page-dropdown" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][pages][]" data-namespace="<?php echo $args['namespace']; ?>" multiple="multiple">
253 <?php
254 $pageLoop = get_pages(['hierarchical' => false]); //get_pages(['hierarchical' => false, 'include' => $pages_values]);
255 foreach ($pageLoop as $objPage) {
256 $_selected = !empty($pages_values) && in_array($objPage->ID, $pages_values) ? 'selected' : '';
257 echo '<option value="' . $objPage->ID . '" ' . $_selected . '>' . $objPage->post_title . '</option>';
258 }
259 ?>
260 </select>
261
262
263 <?php
264 // $page_class = new WidgetOpts_Pages_Checkboxes();
265 // $page_checkboxes = $page_class->walk( $widgetopts_pages, 0, $args );
266 // if ( $page_checkboxes ) {
267 // echo '<div class="widgetopts-ul-pages">' . $page_checkboxes . '</div>';
268 // }
269 ?>
270 </div>
271 </div>
272 </div><!-- end misc tab content -->
273 <?php } ?>
274
275 <?php if (
276 isset($widget_options['settings']['visibility']) &&
277 isset($widget_options['settings']['visibility']['post_type']) &&
278 '1' == $widget_options['settings']['visibility']['post_type']
279 ) { ?>
280 <!-- start types tab content -->
281 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-types" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent extended-widget-opts-tabcontent-pages">
282 <div class="extended-widget-opts-inner-lists" style="height: 230px;padding: 5px;overflow:auto;">
283
284
285 <h4 class="widgetopts-subtitle" id="extended-widget-opts-types"><?php _e('Custom Post Types', 'widget-options'); ?> +/-<br></h4>
286 <div class="extended-widget-opts-types">
287 <?php foreach ($types as $ptype => $type) {
288 // if ( ! $type->has_archive ) {
289 // // don't give the option if there is no archive page
290 // continue;
291 // }
292
293 if (isset($types_values[$ptype]) && $types_values[$ptype] == '1') {
294 $checked = 'checked="checked"';
295 } else {
296 $checked = '';
297 }
298 ?>
299 <p>
300 <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; ?> />
301 <label for="<?php echo $args['id']; ?>-opts-types-<?php echo $ptype; ?>"><?php echo stripslashes($type->labels->name); ?></label>
302 </p>
303 <?php } ?>
304 </div>
305 </div>
306 </div><!-- end types tab content -->
307 <?php } ?>
308
309 <?php if (
310 isset($widget_options['settings']['visibility']) &&
311 isset($widget_options['settings']['visibility']['taxonomies']) &&
312 '1' == $widget_options['settings']['visibility']['taxonomies']
313 ) {
314 $options_page = 1;
315 if (
316 isset($args['params']) &&
317 isset($args['params']['visibility']) &&
318 isset($args['params']['visibility']['tax_terms_page']) &&
319 isset($args['params']['visibility']['tax_terms_page']['category'])
320 ) {
321 $options_page = $args['params']['visibility']['tax_terms_page']['category'];
322 }
323 ?>
324 <!-- start tax tab content -->
325 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-tax" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inner-tabcontent extended-widget-opts-tabcontent-taxonomies">
326 <div class="extended-widget-opts-inner-lists" style="height: 230px;padding: 5px;overflow:auto;">
327 <h4 id="extended-widget-opts-categories"><?php _e('Categories', 'widget-options'); ?> +/-<br>
328 <small>Type atleast 3 characters to initiate the search for Category term</small>
329 </h4>
330 <div class="extended-widget-opts-categories extended-widget-opts-parent-option">
331 <div style="margin-bottom: 10px;">
332 <button type="button" class="widgetopts-search-option-btn" style="width: 75px; background-color: #3D434A; color: #fff; border-radius: 10px 0px 0 10px; border: 1.5px solid #3D434A;">Search</button>
333 <button type="button" class="widgetopts-dropdown-option-btn" style="margin-left: -5px;width: 75px;border-radius: 0 10px 10px 0;color: #777A80;background-color: #fff;border: 1.5px solid #777A80;">Checkbox</button>
334 </div>
335 <select class="widefat extended-widget-opts-select2-dropdown extended-widget-opts-select2-taxonomy-dropdown" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][tax_terms][category][]" data-taxonomy="category" data-namespace="<?php echo $args['namespace']; ?>" multiple="multiple">
336 <?php
337 $taxLoop = get_terms(['taxonomy' => 'category', 'hide_empty' => false]); //get_terms(['taxonomy' => 'category', 'include' => $term_values, 'hide_empty' => false]);
338 foreach ($taxLoop as $objTax) {
339 $term_selected = !empty($term_values) && in_array($objTax->term_id, $term_values) ? 'selected' : '';
340 echo '<option value="' . $objTax->term_id . '" ' . $term_selected . '>' . $objTax->name . '</option>';
341 }
342 ?>
343 </select>
344 </div>
345
346 <p>
347 <strong><?php _e('Select Pages', 'widget-options'); ?></strong><br>
348 <small><?php _e('Select where to show/hide widget.', 'widget-options'); ?></small><br>
349 <select class="widefat" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][tax_terms_page][category]">
350 <option value="1" <?php if ($options_page == 1) {
351 echo 'selected="selected"';
352 } ?>><?php _e('Archive and Single posts', 'widget-options'); ?></option>
353 <option value="2" <?php if ($options_page == 2) {
354 echo 'selected="selected"';
355 } ?>><?php _e('Archive only', 'widget-options'); ?></option>
356 <option value="3" <?php if ($options_page == 3) {
357 echo 'selected="selected"';
358 } ?>><?php _e('Single posts only', 'widget-options'); ?></option>
359 </select>
360 </p>
361
362 <h4 id="extended-widget-opts-taxonomies"><?php _e('Taxonomies', 'widget-options'); ?> +/-</h4>
363 <div class="extended-widget-opts-taxonomies">
364 <?php foreach ($taxonomies as $taxonomy) {
365 if (isset($tax_values[$taxonomy->name]) && $tax_values[$taxonomy->name] == '1') {
366 $checked = 'checked="checked"';
367 } else {
368 $checked = '';
369 }
370 ?>
371 <p>
372 <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; ?> />
373 <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])) {
374 echo ' <small>- ' . $taxonomy->object_type[0] . '</small>';
375 } ?>
376 </p>
377 <?php } ?>
378 </div>
379 </div>
380 <?php $upgrade_link = apply_filters('widget_options_site_url', trailingslashit(WIDGETOPTS_PLUGIN_WEBSITE)); ?>
381 <div class="extended-widget-opts-feature-warning">
382 <small><?php _e('<em>Upgrade to <a href="' . $upgrade_link . '" target="_blank">Pro Version</a> to manage visibility for Custom Taxonomies.</em>', 'widget-options'); ?></small>
383 </div>
384 </div><!-- end tax tab content -->
385 <?php } ?>
386 </div><!-- end .extended-widget-opts-visibility-tabs -->
387 </div><!-- End WordPress Pages tab -->
388 </div><!-- end main tab -->
389
390 </div>
391 <?php
392 }
393 add_action('extended_widget_opts_tabcontent', 'widgetopts_tabcontent_visibility');
394
395 // Page Options
396 function widgetopts_ajax_page_search()
397 {
398 global $wp_version;
399
400 $response = [
401 'results' => [],
402 'pagination' => ['more' => false]
403 ];
404
405 if (!empty($_POST['term'])) {
406 $args = array(
407 'post_type' => 'page',
408 'post_status' => 'publish',
409 's' => $_POST['term'],
410 );
411
412 $is_6_3_and_above = version_compare($wp_version, '6.3', '>=');
413 if ($is_6_3_and_above) {
414 $args['cache_results'] = apply_filters('cache_widgetopts_ajax_page_search', true);
415 }
416
417 $query = new WP_Query($args);
418 while ($query->have_posts()) {
419 $query->the_post();
420 $response['results'][] = [
421 'id' => get_the_ID(),
422 'text' => get_the_title()
423 ];
424 }
425 }
426
427 echo json_encode($response);
428 die();
429 }
430 add_action('wp_ajax_widgetopts_ajax_page_search', 'widgetopts_ajax_page_search');
431
432 // Taxonomy Options
433 function widgetopts_ajax_taxonomy_search()
434 {
435 $response = [
436 'results' => [],
437 'pagination' => ['more' => false]
438 ];
439
440 if (!empty($_POST['term']) && $_POST['taxonomy']) {
441 $args = array(
442 'taxonomy' => array($_POST['taxonomy']),
443 'fields' => 'all',
444 'name__like' => $_POST['term'],
445 'hide_empty' => false
446 );
447
448 $terms = get_terms($args);
449 foreach ($terms as $term) {
450 $response['results'][] = [
451 'id' => $term->term_id,
452 'text' => $term->name
453 ];
454 }
455 }
456
457 echo json_encode($response);
458 die();
459 }
460 add_action('wp_ajax_widgetopts_ajax_taxonomy_search', 'widgetopts_ajax_taxonomy_search'); ?>