PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.2.4
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.2.4
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 months ago animation.php 2 months ago behavior.php 2 months ago days-dates.php 2 months ago devices.php 2 months ago settings.php 2 months ago state.php 2 months ago styling.php 2 months ago upsell.php 2 months ago visibility.php 2 months ago
visibility.php
487 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 $pargs = array(
255 'hierarchical' => true,
256 'child_of' => 0, // Display all pages regardless of parent
257 'parent' => -1, // Display all pages regardless of parent
258 'sort_order' => 'ASC',
259 'sort_column' => 'menu_order, post_title'
260 );
261
262 $pageLoop = get_pages($pargs);
263
264 if ($pageLoop) {
265 foreach ($pageLoop as $objPage) {
266 $depth = count(get_ancestors($objPage->ID, 'page'));
267 // Determine indentation for hierarchical display
268 $indent = str_repeat('-', $depth);
269
270 // Check if the page is selected based on form submission
271 $_selected_page = !empty($pages_values) && in_array($objPage->ID, $pages_values) ? 'selected' : '';
272
273 echo '<option value="' . $objPage->ID . '" ' . $_selected_page . '>' . $indent . esc_html($objPage->post_title) . '</option>';
274 }
275 }
276 ?>
277 </select>
278
279
280 <?php
281 // $page_class = new WidgetOpts_Pages_Checkboxes();
282 // $page_checkboxes = $page_class->walk( $widgetopts_pages, 0, $args );
283 // if ( $page_checkboxes ) {
284 // echo '<div class="widgetopts-ul-pages">' . $page_checkboxes . '</div>';
285 // }
286 ?>
287 </div>
288 </div>
289 </div><!-- end misc tab content -->
290 <?php } ?>
291
292 <?php if (
293 isset($widget_options['settings']['visibility']) &&
294 isset($widget_options['settings']['visibility']['post_type']) &&
295 '1' == $widget_options['settings']['visibility']['post_type']
296 ) { ?>
297 <!-- start types tab content -->
298 <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">
299 <div class="extended-widget-opts-inner-lists" style="height: 230px;padding: 5px;overflow:auto;">
300
301
302 <h4 class="widgetopts-subtitle" id="extended-widget-opts-types"><?php _e('Custom Post Types', 'widget-options'); ?> +/-<br></h4>
303 <div class="extended-widget-opts-types">
304 <?php foreach ($types as $ptype => $type) {
305 // if ( ! $type->has_archive ) {
306 // // don't give the option if there is no archive page
307 // continue;
308 // }
309
310 if (isset($types_values[$ptype]) && $types_values[$ptype] == '1') {
311 $checked = 'checked="checked"';
312 } else {
313 $checked = '';
314 }
315 ?>
316 <p>
317 <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; ?> />
318 <label for="<?php echo $args['id']; ?>-opts-types-<?php echo $ptype; ?>"><?php echo stripslashes($type->labels->name); ?></label>
319 </p>
320 <?php } ?>
321 </div>
322 </div>
323 </div><!-- end types tab content -->
324 <?php } ?>
325
326 <?php if (
327 isset($widget_options['settings']['visibility']) &&
328 isset($widget_options['settings']['visibility']['taxonomies']) &&
329 '1' == $widget_options['settings']['visibility']['taxonomies']
330 ) {
331 $options_page = 1;
332 if (
333 isset($args['params']) &&
334 isset($args['params']['visibility']) &&
335 isset($args['params']['visibility']['tax_terms_page']) &&
336 isset($args['params']['visibility']['tax_terms_page']['category'])
337 ) {
338 $options_page = $args['params']['visibility']['tax_terms_page']['category'];
339 }
340 ?>
341 <!-- start tax tab content -->
342 <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">
343 <div class="extended-widget-opts-inner-lists" style="height: 230px;padding: 5px;overflow:auto;">
344 <h4 id="extended-widget-opts-categories"><?php _e('Categories', 'widget-options'); ?> +/-<br>
345 <small>Type atleast 3 characters to initiate the search for Category term</small>
346 </h4>
347 <div class="extended-widget-opts-categories extended-widget-opts-parent-option">
348 <div style="margin-bottom: 10px;">
349 <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>
350 <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>
351 </div>
352 <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">
353 <?php
354 $taxLoop = get_terms(['taxonomy' => 'category', 'hide_empty' => false]); //get_terms(['taxonomy' => 'category', 'include' => $term_values, 'hide_empty' => false]);
355 foreach ($taxLoop as $objTax) {
356 $term_selected = !empty($term_values) && in_array($objTax->term_id, $term_values) ? 'selected' : '';
357 echo '<option value="' . $objTax->term_id . '" ' . $term_selected . '>' . $objTax->name . '</option>';
358 }
359 ?>
360 </select>
361
362 <p style="margin-top: 10px;">
363 <strong><?php _e('Select Pages', 'widget-options'); ?></strong><br>
364 <small><?php _e('Select where to show/hide widget.', 'widget-options'); ?></small><br>
365 <select class="widefat" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][tax_terms_page][category]">
366 <option value="1" <?php if ($options_page == 1) {
367 echo 'selected="selected"';
368 } ?>><?php _e('Archive and Single posts', 'widget-options'); ?></option>
369 <option value="2" <?php if ($options_page == 2) {
370 echo 'selected="selected"';
371 } ?>><?php _e('Archive only', 'widget-options'); ?></option>
372 <option value="3" <?php if ($options_page == 3) {
373 echo 'selected="selected"';
374 } ?>><?php _e('Single posts only', 'widget-options'); ?></option>
375 </select>
376 </p>
377 </div>
378
379 <h4 id="extended-widget-opts-taxonomies"><?php _e('Taxonomies', 'widget-options'); ?> +/-</h4>
380 <div class="extended-widget-opts-taxonomies">
381 <?php foreach ($taxonomies as $taxonomy) {
382 if (isset($tax_values[$taxonomy->name]) && $tax_values[$taxonomy->name] == '1') {
383 $checked = 'checked="checked"';
384 } else {
385 $checked = '';
386 }
387 ?>
388 <p>
389 <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; ?> />
390 <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])) {
391 echo ' <small>- ' . $taxonomy->object_type[0] . '</small>';
392 } ?>
393 </p>
394 <?php } ?>
395 </div>
396 </div>
397 <?php $upgrade_link = apply_filters('widget_options_site_url', trailingslashit(WIDGETOPTS_PLUGIN_WEBSITE)); ?>
398 <div class="extended-widget-opts-feature-warning">
399 <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>
400 </div>
401 </div><!-- end tax tab content -->
402 <?php } ?>
403 </div><!-- end .extended-widget-opts-visibility-tabs -->
404 </div><!-- End WordPress Pages tab -->
405 </div><!-- end main tab -->
406
407 </div>
408 <?php
409 }
410 add_action('extended_widget_opts_tabcontent', 'widgetopts_tabcontent_visibility');
411
412 // Page Options
413 function widgetopts_ajax_page_search()
414 {
415 if (!current_user_can('edit_posts')) {
416 wp_send_json_error('You do not have permission to search pages.', 403);
417 exit;
418 }
419
420 global $wp_version;
421
422 $response = [
423 'results' => [],
424 'pagination' => ['more' => false]
425 ];
426
427 if (!empty($_POST['term'])) {
428 $args = array(
429 'post_type' => 'page',
430 'post_status' => 'publish',
431 's' => $_POST['term'],
432 );
433
434 $is_6_3_and_above = version_compare($wp_version, '6.3', '>=');
435 if ($is_6_3_and_above) {
436 $args['cache_results'] = apply_filters('cache_widgetopts_ajax_page_search', true);
437 }
438
439 $query = new WP_Query($args);
440 while ($query->have_posts()) {
441 $query->the_post();
442 $response['results'][] = [
443 'id' => get_the_ID(),
444 'text' => get_the_title()
445 ];
446 }
447 }
448
449 echo json_encode($response);
450 die();
451 }
452 add_action('wp_ajax_widgetopts_ajax_page_search', 'widgetopts_ajax_page_search');
453
454 // Taxonomy Options
455 function widgetopts_ajax_taxonomy_search()
456 {
457 if (!current_user_can('edit_posts')) {
458 wp_send_json_error('You do not have permission to search taxonomies.', 403);
459 exit;
460 }
461
462 $response = [
463 'results' => [],
464 'pagination' => ['more' => false]
465 ];
466
467 if (!empty($_POST['term']) && $_POST['taxonomy']) {
468 $args = array(
469 'taxonomy' => array($_POST['taxonomy']),
470 'fields' => 'all',
471 'name__like' => $_POST['term'],
472 'hide_empty' => false
473 );
474
475 $terms = get_terms($args);
476 foreach ($terms as $term) {
477 $response['results'][] = [
478 'id' => $term->term_id,
479 'text' => $term->name
480 ];
481 }
482 }
483
484 echo json_encode($response);
485 die();
486 }
487 add_action('wp_ajax_widgetopts_ajax_taxonomy_search', 'widgetopts_ajax_taxonomy_search'); ?>