PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.2.0
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.2.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 / widgets / option-tabs / settings.php
widget-options / includes / widgets / option-tabs Last commit date
alignment.php 3 months ago animation.php 3 months ago behavior.php 3 months ago days-dates.php 3 months ago devices.php 3 months ago settings.php 3 months ago state.php 3 months ago styling.php 3 months ago upsell.php 3 months ago visibility.php 3 months ago
settings.php
261 lines
1 <?php
2
3 /**
4 * Settings 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 Settings 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 alignment options
23 */
24 if (!function_exists('widgetopts_tab_settings')) :
25 function widgetopts_tab_settings($args)
26 { ?>
27 <li class="extended-widget-opts-tab-class">
28 <a href="#extended-widget-opts-tab-<?php echo $args['id']; ?>-class" title="<?php _e('Logic & ACF', 'widget-options'); ?>"><span class="dashicons dashicons-code-standards"></span> <span class="tabtitle"><?php _e('Logic & ACF', 'widget-options'); ?></span></a>
29 </li>
30 <?php
31 }
32 add_action('extended_widget_opts_tabs', 'widgetopts_tab_settings', 8);
33 endif;
34
35 /**
36 * Called on 'extended_widget_opts_tabcontent'
37 * create new tab content options for alignment options
38 */
39 if (!function_exists('widgetopts_tabcontent_settings')) :
40 function widgetopts_tabcontent_settings($args)
41 {
42 global $widget_options;
43
44 $id = '';
45 $classes = '';
46 $logic_snippet_id = '';
47 $legacy_logic = '';
48 $selected = 0;
49 $check = '';
50 if (isset($args['params']) && isset($args['params']['class'])) {
51 if (isset($args['params']['class']['id'])) {
52 $id = $args['params']['class']['id'];
53 }
54 if (isset($args['params']['class']['classes'])) {
55 $classes = $args['params']['class']['classes'];
56 }
57 if (isset($args['params']['class']['selected'])) {
58 $selected = $args['params']['class']['selected'];
59 }
60 // New snippet-based logic
61 if (isset($args['params']['class']['logic_snippet_id'])) {
62 $logic_snippet_id = $args['params']['class']['logic_snippet_id'];
63 }
64 // Legacy inline logic code (old format)
65 if (isset($args['params']['class']['logic']) && !empty($args['params']['class']['logic'])) {
66 $legacy_logic = $args['params']['class']['logic'];
67 // Flag that legacy migration is needed
68 if (!get_option('wopts_display_logic_migration_required', false)) {
69 update_option('wopts_display_logic_migration_required', true);
70 }
71 }
72 if (isset($args['params']['class']['title']) && $args['params']['class']['title'] == '1') {
73 $check = 'checked="checked"';
74 }
75 }
76
77 if (isset($args['params']) && isset($args['params']['visibility'])) {
78 if (isset($args['params']['visibility']['acf'])) {
79 $acf_values = $args['params']['visibility']['acf'];
80 }
81 }
82
83 $predefined = array();
84 if (isset($widget_options['settings']['classes']) && isset($widget_options['settings']['classes']['classlists']) && !empty($widget_options['settings']['classes']['classlists'])) {
85 $predefined = $widget_options['settings']['classes']['classlists'];
86 }
87 ?>
88 <div id="extended-widget-opts-tab-<?php echo $args['id']; ?>-class" class="extended-widget-opts-tabcontent extended-widget-opts-inside-tabcontent extended-widget-opts-tabcontent-class">
89
90 <div class="extended-widget-opts-settings-tabs extended-widget-opts-inside-tabs">
91 <input type="hidden" id="extended-widget-opts-settings-selectedtab" value="<?php echo $selected; ?>" name="<?php echo $args['namespace']; ?>[extended_widget_opts][class][selected]" />
92 <!-- start tab nav -->
93 <ul style="margin-top: 10px;" class="extended-widget-opts-settings-tabnav-ul">
94
95 <?php if ('activate' == $widget_options['logic']) { ?>
96 <li class="extended-widget-opts-settings-tab-logic">
97 <a href="#extended-widget-opts-settings-tab-<?php echo $args['id']; ?>-logic" title="<?php _e('Display Logic', 'widget-options'); ?>"><?php _e('Logic', 'widget-options'); ?></a>
98 </li>
99 <?php } ?>
100
101 <?php if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) { ?>
102 <li class="extended-widget-opts-visibility-tab-acf">
103 <a href="#extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-acf" title="<?php _e('ACF', 'widget-options'); ?>"><?php _e('ACF', 'widget-options'); ?></a>
104 </li>
105 <?php } ?>
106 <div class="extended-widget-opts-clearfix"></div>
107 </ul><!-- end tab nav -->
108 <div class="extended-widget-opts-clearfix"></div>
109
110 <?php if ('activate' == $widget_options['logic']) { ?>
111 <!-- start logic tab content -->
112 <div id="extended-widget-opts-settings-tab-<?php echo $args['id']; ?>-logic" class="extended-widget-opts-settings-tabcontent extended-widget-opts-inner-tabcontent">
113 <div class="widget-opts-logic">
114
115 <?php
116 // Get available snippets
117 $snippets = array();
118 if (class_exists('WidgetOpts_Snippets_CPT')) {
119 $snippets = WidgetOpts_Snippets_CPT::get_all_snippets();
120 }
121
122 $snippet_desc = '';
123 if (!empty($logic_snippet_id) && !empty($snippets)) {
124 foreach ($snippets as $s) {
125 if ($s['id'] == $logic_snippet_id) {
126 $snippet_desc = $s['description'];
127 break;
128 }
129 }
130 }
131
132 // Show Legacy Logic OR Snippet dropdown — mutually exclusive
133 $show_legacy = (!empty($legacy_logic) && empty($logic_snippet_id));
134 ?>
135
136 <?php if ($show_legacy) : ?>
137 <div class="widgetopts-legacy-logic-warning" style="margin-bottom: 15px;">
138 <p><strong><?php _e('Legacy Display Logic Code', 'widget-options'); ?></strong></p>
139 <textarea readonly="readonly" class="widefat" rows="4" style="background: #f9f2f4; color: #c7254e; font-family: monospace; font-size: 12px; cursor: not-allowed;"><?php echo esc_textarea($legacy_logic); ?></textarea>
140 <input type="hidden" name="<?php echo $args['namespace']; ?>[extended_widget_opts][class][logic_cleared]" value="" class="widgetopts-logic-cleared-field" />
141 <p style="margin-top: 8px; padding: 8px 12px; background: #fff3cd; border-left: 4px solid #ffc107; color: #856404;">
142 <?php _e('This widget uses legacy inline display logic code that needs to be migrated to the new snippet-based system.', 'widget-options'); ?>
143 <?php if (current_user_can(WIDGETOPTS_MIGRATION_PERMISSIONS)) : ?>
144 <br><a href="<?php echo esc_url(admin_url('options-general.php?page=widgetopts_migration')); ?>" target="_blank">
145 <?php _e('Go to Migration Page', 'widget-options'); ?> &rarr;
146 </a>
147 <?php endif; ?>
148 </p>
149 <button type="button" class="button widgetopts-clear-legacy-btn" style="margin-top:8px;background:#dc3545;color:#fff;border-color:#dc3545;font-size:12px;" onclick="(function(btn){var $btn=jQuery(btn);var $wrap=$btn.closest('.widgetopts-legacy-logic-warning');var $logic=$btn.closest('.widget-opts-logic');var $widget=$btn.closest('.widget');var $inside=$widget.children('.widget-inside');var $cleared=$wrap.find('.widgetopts-logic-cleared-field');var $snippet=$logic.find('.widgetopts-logic-snippet-select');var $saveButton=$inside.find('.widget-control-save');var widgetId=$inside.find('.widget-id').val();var saveLabel=(window.wp&&wp.i18n&&wp.i18n.__)?wp.i18n.__( 'Save' ):'Save';$cleared.val('1').trigger('input').trigger('change');$snippet.val('').trigger('change');$wrap.slideUp();$logic.find('.widgetopts-snippet-section').slideDown();if(window.wpWidgets&&widgetId){window.wpWidgets.dirtyWidgets[widgetId]=true;}$widget.addClass('widget-dirty');$saveButton.prop('disabled',false).removeClass('disabled').val(saveLabel);$inside.trigger('input').trigger('change');$widget.find('.widget-control-close-wrapper .widget-control-close').text('Cancel');})(this)">
150 <?php _e('Clear Legacy Logic', 'widget-options'); ?>
151 </button>
152 </div>
153 <?php endif; ?>
154
155 <div class="widgetopts-snippet-section"<?php echo $show_legacy ? ' style="display:none;"' : ''; ?>>
156 <p><strong><?php _e('Display Logic Snippet', 'widget-options'); ?></strong></p>
157 <p><small><?php _e('Select a logic snippet to control when this widget is displayed.', 'widget-options'); ?></small></p>
158
159 <select class="widefat widgetopts-logic-snippet-select widgetopts-select2-snippets" name="<?php echo $args['namespace']; ?>[extended_widget_opts][class][logic_snippet_id]" style="margin-bottom: 10px; width: 100%;" data-placeholder="<?php esc_attr_e('— No Logic (Always Show) —', 'widget-options'); ?>">
160 <option value=""><?php _e('— No Logic (Always Show) —', 'widget-options'); ?></option>
161 <?php foreach ($snippets as $snippet) : ?>
162 <option value="<?php echo esc_attr($snippet['id']); ?>" <?php selected($logic_snippet_id, $snippet['id']); ?>>
163 <?php echo esc_html($snippet['title']); ?>
164 </option>
165 <?php endforeach; ?>
166 </select>
167
168 <p class="widgetopts-snippet-desc description" style="font-style: italic; color: #666;<?php echo empty($snippet_desc) ? ' display:none;' : ''; ?>">
169 <?php echo esc_html($snippet_desc); ?>
170 </p>
171
172 <?php if (current_user_can('manage_options')) : ?>
173 <p style="margin-top: 15px;">
174 <a href="<?php echo admin_url('edit.php?post_type=widgetopts_snippet'); ?>" target="_blank" class="button button-small">
175 <?php _e('Manage Logic Snippets', 'widget-options'); ?>
176 </a>
177 </p>
178 <?php endif; ?>
179 </div>
180 </div>
181 </div><!-- end logic tab content -->
182 <?php } ?>
183
184 <!-- Start ACF tab -->
185 <?php if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) : ?>
186
187 <?php if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) : ?>
188 <div id="extended-widget-opts-visibility-tab-<?php echo $args['id']; ?>-acf" class="extended-widget-opts-visibility-tabcontent extended-widget-opts-inside-tabcontent extended-widget-opts-inner-tabcontent">
189 <p class="widgetopts-subtitle" style="display: none !important;"><?php _e('ACF', 'widget-options'); ?></p>
190 <?php
191 $fields = array();
192
193 if (function_exists('acf_get_field_groups')) {
194 $groups = acf_get_field_groups();
195 if (is_array($groups)) {
196 foreach ($groups as $group) {
197 $fields[$group['ID']] = array('title' => $group['title'], 'fields' => acf_get_fields($group));
198 }
199 }
200 } else {
201 $groups = apply_filters('acf/get_field_groups', array());
202 if (is_array($groups)) {
203 foreach ($groups as $group) {
204 $fields[$group['id']] = array('title' => $group['title'], 'fields' => apply_filters('acf/field_group/get_fields', array(), $group['id']));
205 }
206 }
207 }
208 ?>
209 <p><strong><?php _e('Hide/Show', 'widget-options'); ?></strong>
210 <select class="widefat" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][acf][visibility]">
211 <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>
212 <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>
213 </select>
214 </p>
215
216 <p><strong><?php _e('Choose ACF Field', 'widget-options'); ?></strong>
217 <select class="widefat" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][acf][field]">
218 <option value=""><?php _e('Select Field', 'widget-options'); ?></option>
219 <?php
220 if (!empty($fields)) {
221 foreach ($fields as $k => $field) { ?>
222 <optgroup label="<?php echo $field['title']; ?>">
223 <?php foreach ($field['fields'] as $key => $f) { ?>
224 <option value="<?php echo $f['key']; ?>" <?php echo (isset($acf_values['field']) && $acf_values['field'] == $f['key']) ? 'selected="selected"' : '' ?>><?php echo $f['label']; ?></option>
225 <?php } ?>
226 </optgroup>
227 <?php }
228 } ?>
229 </select>
230 </p>
231 <p><strong><?php _e('Condition', 'widget-options'); ?></strong>
232 <select class="widefat" name="<?php echo $args['namespace']; ?>[extended_widget_opts][visibility][acf][condition]">
233 <option value=""><?php _e('Select Condition', 'widget-options'); ?></option>
234 <optgroup label="<?php _e('Conditional', 'widget-options'); ?>">
235 <option value="equal" <?php echo (isset($acf_values['condition']) && $acf_values['condition'] == 'equal') ? 'selected="selected"' : '' ?>><?php _e('Is Equal to', 'widget-options'); ?></option>
236 <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>
237 <option value="contains" <?php echo (isset($acf_values['condition']) && $acf_values['condition'] == 'contains') ? 'selected="selected"' : '' ?>><?php _e('Contains', 'widget-options'); ?></option>
238 <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>
239 </optgroup>
240 <optgroup label="<?php _e('Value Based', 'widget-options'); ?>">
241 <option value="empty" <?php echo (isset($acf_values['condition']) && $acf_values['condition'] == 'empty') ? 'selected="selected"' : '' ?>><?php _e('Is Empty', 'widget-options'); ?></option>
242 <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>
243 </optgroup>
244 </select>
245 </p>
246 <p><strong><?php _e('Conditional Value', 'widget-options'); ?></strong>
247 <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>
248 </p>
249 </div>
250 <?php endif; ?>
251 <?php endif; ?>
252 <!-- End ACF tab -->
253
254 </div><!-- end .extended-widget-opts-settings-tabs -->
255
256
257 </div>
258 <?php
259 }
260 add_action('extended_widget_opts_tabcontent', 'widgetopts_tabcontent_settings');
261 endif; ?>