PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.8
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.8
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 / scripts.php
widget-options / includes Last commit date
admin 1 year ago pagebuilders 1 year ago widgets 1 year ago ajax-functions.php 2 years ago extras.php 1 year ago install.php 2 years ago scripts.php 1 year ago transient.php 2 years ago
scripts.php
364 lines
1 <?php
2
3 /**
4 * Scripts
5 *
6 * @copyright Copyright (c) 2016, Jeffrey Carandang
7 * @since 3.0
8 */
9
10 // Exit if accessed directly
11 if (!defined('ABSPATH')) exit;
12
13 /**
14 * Load Scripts
15 *
16 * Enqueues the required scripts.
17 *
18 * @since 3.0
19 * @return void
20 */
21
22 function widgetopts_load_scripts()
23 {
24 global $pagenow;
25 $css_dir = WIDGETOPTS_PLUGIN_URL . 'assets/css/';
26 $js_dir = WIDGETOPTS_PLUGIN_URL . 'assets/js/';
27 wp_enqueue_style('widgetopts-styles', $css_dir . 'widget-options.css', array(), WIDGETOPTS_VERSION);
28
29 if (isset($pagenow) && $pagenow === 'customize.php') {
30 wp_add_inline_script(
31 'customize-controls',
32 '(function(){
33 document.querySelector("#save").onclick = function() {
34 setTimeout(function(){wp.customize.previewer.refresh();}, 3000);
35 }
36 })();',
37 'after'
38 );
39 }
40
41 if (!is_admin()) {
42 // Check if the device is NOT mobile (i.e., it's a desktop)
43 if (!wp_is_mobile()) {
44 // Enqueue the script for desktop devices
45 wp_enqueue_script(
46 'widgetopts-resize-script', // Handle name
47 $js_dir . 'widgetopts.resize.js',
48 array(), // Dependencies (optional)
49 WIDGETOPTS_VERSION, // Version (optional)
50 true // Load in footer (optional)
51 );
52 }
53 }
54 }
55 add_action('wp_enqueue_scripts', 'widgetopts_load_scripts');
56 add_action('customize_controls_enqueue_scripts', 'widgetopts_load_scripts');
57
58 /**
59 * Load Admin Scripts
60 *
61 * Enqueues the required admin scripts.
62 *
63 * @since 3.0
64 * @global $widget_options
65 * @param string $hook Page hook
66 * @return void
67 */
68 if (!function_exists('widgetopts_load_admin_scripts')) :
69 function widgetopts_load_admin_scripts($hook)
70 {
71 global $widget_options, $wp_version;
72
73 $in_footer_args = false;
74 $is_6_3_and_above = version_compare($wp_version, '6.3', '>=');
75 if ($is_6_3_and_above) {
76 $in_footer_args = array(
77 'in_footer' => true,
78 'strategy' => 'defer',
79 );
80 }
81
82 $js_dir = WIDGETOPTS_PLUGIN_URL . 'assets/js/';
83 $css_dir = WIDGETOPTS_PLUGIN_URL . 'assets/css/';
84 $is_siteorigin = (isset($widget_options['siteorigin'])) ? $widget_options['siteorigin'] : '';
85
86 // Use minified libraries if SCRIPT_DEBUG is turned off
87 $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
88
89 wp_enqueue_style('widgetopts-admin-styles', $css_dir . 'admin.css', array(), WIDGETOPTS_VERSION);
90
91 wp_enqueue_script(
92 'widgetopts-global-script',
93 $js_dir . 'widgetopts.global.js',
94 array('jquery'),
95 WIDGETOPTS_VERSION,
96 ($is_6_3_and_above ? $in_footer_args : true)
97 );
98
99 //load only on admin pages with widgets
100 if (($is_siteorigin) || (!$is_siteorigin && in_array($hook, apply_filters('widgetopts_load_option-tabs_scripts', array('widgets.php', 'customize.php', 'nav-menus.php'))))) {
101
102 if (!in_array($hook, apply_filters('widgetopts_exclude_jqueryui', array('toplevel_page_et_divi_options', 'toplevel_page_wpcf7', 'edit.php')))) {
103 wp_enqueue_style('jquery-ui');
104 }
105
106 if (in_array($hook, apply_filters('widgetopts_load_liveFilter_scripts', array('widgets.php', 'nav-menus.php')))) {
107 wp_enqueue_script(
108 'jquery-liveFilter',
109 plugins_url('assets/js/jquery.liveFilter.js', dirname(__FILE__)),
110 array('jquery'),
111 WIDGETOPTS_VERSION,
112 ($is_6_3_and_above ? $in_footer_args : true)
113 );
114 }
115
116 wp_enqueue_script(
117 'jquery-widgetopts-option-tabs',
118 plugins_url('assets/js/wpWidgetOpts.js', dirname(__FILE__)),
119 array('jquery', 'jquery-ui-core', 'jquery-ui-tabs', 'jquery-ui-datepicker'),
120 WIDGETOPTS_VERSION,
121 ($is_6_3_and_above ? $in_footer_args : true)
122 );
123
124
125 wp_enqueue_style('jquery-widgetopts-select2-css', plugins_url('assets/css/select2.min.css', dirname(__FILE__)), array(), WIDGETOPTS_VERSION);
126
127 if (!wp_script_is('select2', 'enqueued')) {
128 wp_enqueue_script(
129 'jquery-widgetopts-select2-script',
130 $js_dir . 'select2.min.js',
131 array('jquery'),
132 WIDGETOPTS_VERSION,
133 ($is_6_3_and_above ? $in_footer_args : true)
134 );
135 }
136
137 wp_enqueue_style('jquery-widgetopts-multiselect-css', plugins_url('assets/css/bootstrap-multiselect.min.css', dirname(__FILE__)), array(), WIDGETOPTS_VERSION);
138 wp_enqueue_script(
139 'jquery-widgetopts-multiselect-script',
140 $js_dir . 'bootstrap-multiselect.min.js',
141 array('jquery'),
142 WIDGETOPTS_VERSION,
143 ($is_6_3_and_above ? $in_footer_args : true)
144 );
145
146 $form = '<div id="widgetopts-widgets-chooser">
147 <label class="screen-reader-text" for="widgetopts-search-chooser">' . __('Search Sidebar', 'widget-options') . '</label>
148 <input type="text" id="widgetopts-search-chooser" class="widgetopts-widgets-search" placeholder="' . __('Search sidebar&hellip;', 'widget-options') . '" />
149 <div class="widgetopts-search-icon" aria-hidden="true"></div>
150 <button type="button" class="widgetopts-clear-results"><span class="screen-reader-text">' . __('Clear Results', 'widget-options') . '</span></button>
151 <p class="screen-reader-text" id="widgetopts-chooser-desc">' . __('The search results will be updated as you type.', 'widget-options') . '</p>
152 </div>';
153
154 $btn_controls = '';
155 if (isset($widget_options['move']) && 'activate' == $widget_options['move']) {
156 $btn_controls .= ' | <button type="button" class="button-link widgetopts-control" data-action="move">' . __('Move', 'widget-options') . '</button>';
157 }
158
159 $sidebaropts = '';
160 if (isset($widget_options['widget_area']) && 'activate' == $widget_options['widget_area']) {
161 /* Updated by Haive Vistal - 04/20/2023 - Make sure no empty space in under the widgets if no activated links */
162 $remove_widget_link = 0;
163 $download_backup_link = 0;
164 $delete_all_widget_link = 0;
165
166 if (isset($widget_options['settings']['widget_area']) && isset($widget_options['settings']['widget_area']['remove']) && '1' == $widget_options['settings']['widget_area']['remove']) {
167 $remove_widget_link = 1;
168 }
169 if (isset($widget_options['settings']['widget_area']) && isset($widget_options['settings']['widget_area']['backup']) && '1' == $widget_options['settings']['widget_area']['backup']) {
170 $download_backup_link = 1;
171 }
172
173 if (isset($widget_options['settings']['widget_area']) && isset($widget_options['settings']['widget_area']['remove']) && '1' == $widget_options['settings']['widget_area']['remove']) {
174 $delete_all_widget_link = 1;
175 }
176
177 if ($remove_widget_link == 1 || $download_backup_link == 1 || $delete_all_widget_link == 1) {
178 $sidebaropts = '<div class="widgetopts-sidebaropts">';
179 if ($remove_widget_link == 1) {
180 $sidebaropts .= '<a href="#" class="sidebaropts-clear">
181 <span class="dashicons dashicons-warning"></span> ' . __('Remove All Widgets', 'widget-options') . '
182 </a>';
183 }
184 if ($download_backup_link == 1) {
185 $sidebaropts .= '<a href="' . esc_url(wp_nonce_url(admin_url('tools.php?page=widgetopts_migrator_settings&action=export&single_sidebar=__sidebaropts__'), 'widgeopts_export', 'widgeopts_nonce_export')) . '">
186 <span class="dashicons dashicons-download"></span> ' . __('Download Backup', 'widget-options') . '
187 </a>';
188 }
189 if ($delete_all_widget_link == 1) {
190 $sidebaropts .= '<div class="sidebaropts-confirm"><p>
191 ' . __('Are you sure you want to DELETE ALL widgets associated to __sidebar_opts__?', 'widget-options') . '
192 </p>
193 <button class="button">' . __('No', 'widget-options') . '</button>
194 <button class="button button-primary">' . __('Yes', 'widget-options') . '</button>
195 </div>';
196 }
197 $sidebaropts .= '</div>';
198 }
199 }
200
201 /* Added by Haive Vistal - 04/20/2023 - Default link for all widgets to go through widget options panel settings */
202 // $sidebaropts .= '<div class="widgetopts-super widgetopts-sidebaropts">';
203 // $sidebaropts .= '<a href="'. esc_url( wp_nonce_url( admin_url('options-general.php?page=widgetopts_plugin_settings'), 'widgeopts_setings', 'widgeopts_nonce_settings') ) .'">
204 // <span class="dashicons dashicons-admin-settings"></span> '. __( 'Enable more Widget Options superpowers', 'widget-options' ) .'
205 // </a>';
206 // $sidebaropts .= '</div>';
207
208 wp_localize_script('jquery-widgetopts-option-tabs', 'widgetopts10n', array('ajax_url' => admin_url('admin-ajax.php'), 'opts_page' => esc_url(admin_url('options-general.php?page=widgetopts_plugin_settings')), 'search_form' => $form, 'sidebaropts' => $sidebaropts, 'controls' => $btn_controls, 'translation' => array('manage_settings' => __('Manage Widget Options', 'widget-options'), 'search_chooser' => __('Search sidebar&hellip;', 'widget-options'))));
209 } else {
210 wp_localize_script('widgetopts-global-script', 'widgetopts10n', array('ajax_url' => admin_url('admin-ajax.php'), 'opts_page' => esc_url(admin_url('options-general.php?page=widgetopts_plugin_settings')), 'translation' => array('manage_settings' => __('Manage Widget Options', 'widget-options'), 'search_chooser' => __('Search sidebar&hellip;', 'widget-options'))));
211 }
212
213 if (in_array($hook, apply_filters('widgetopts_load_settings_scripts', array('settings_page_widgetopts_plugin_settings')))) {
214 wp_register_script(
215 'jquery-widgetopts-settings',
216 $js_dir . 'settings' . $suffix . '.js',
217 array('jquery'),
218 WIDGETOPTS_VERSION,
219 ($is_6_3_and_above ? $in_footer_args : true)
220 );
221
222 $translation = array(
223 'save_settings' => __('Save Settings', 'widget-options'),
224 'close_settings' => __('Close', 'widget-options'),
225 'show_settings' => __('Configure Settings', 'widget-options'),
226 'hide_settings' => __('Hide Settings', 'widget-options'),
227 'show_description' => __('Learn More', 'widget-options'),
228 'hide_description' => __('Hide Details', 'widget-options'),
229 'show_information' => __('Show Details', 'widget-options'),
230 'activate' => __('Enable', 'widget-options'),
231 'deactivate' => __('Disable', 'widget-options'),
232 'successful_save' => __('Settings saved successfully for %1$s.', 'widget-options'),
233 'deactivate_btn' => __('Deactivate License', 'widget-options'),
234 'activate_btn' => __('Activate License', 'widget-options'),
235 'status_valid' => __('Valid', 'widget-options'),
236 'status_invalid' => __('Invalid', 'widget-options'),
237 );
238
239 wp_enqueue_script('jquery-widgetopts-settings');
240 wp_localize_script('jquery-widgetopts-settings', 'widgetopts', array('translation' => $translation, 'ajax_action' => 'widgetopts_ajax_settings', 'ajax_nonce' => wp_create_nonce('widgetopts-settings-nonce'),));
241 }
242 }
243 add_action('admin_enqueue_scripts', 'widgetopts_load_admin_scripts', 100);
244 endif;
245
246 if (!function_exists('widgetopts_widgets_footer')) {
247 function widgetopts_widgets_footer()
248 {
249 global $widget_options; ?>
250 <div class="widgetsopts-chooser" style="display:none;">
251 <?php if (isset($widget_options['search']) && 'activate' == $widget_options['search']) : ?>
252 <div id="widgetopts-widgets-chooser">
253 <label class="screen-reader-text" for="widgetopts-search-chooser"><?php _e('Search Sidebar', 'widget-options'); ?></label>
254 <input type="text" id="widgetsopts-widgets-search" class="widgetopts-widgets-search widgetsopts-widgets-search" placeholder="Search sidebar…">
255 <div class="widgetopts-search-icon" aria-hidden="true"></div>
256 <button type="button" class="widgetopts-clear-results"><span class="screen-reader-text"><?php _e('Clear Results', 'widget-options'); ?></span></button>
257 <p class="screen-reader-text" id="widgetopts-chooser-desc"><?php _e('The search results will be updated as you type.', 'widget-options'); ?></p>
258 </div>
259 <?php endif; ?>
260 <ul class="widgetopts-chooser-sidebars"></ul>
261 <div class="widgetsopts-chooser-actions">
262 <button class="button widgetsopts-chooser-cancel"><?php _e('Cancel', 'widget-options'); ?></button>
263 <button class="button button-primary widgetopts-chooser-action"><span><?php _e('Move', 'widget-options'); ?></span> <?php _e('Widget', 'widget-options'); ?></button>
264 </div>
265 </div>
266 <?php }
267 add_action('admin_footer-widgets.php', 'widgetopts_widgets_footer');
268 }
269
270 if (!function_exists('widgetopts_widgets_footer_additional_script')) {
271 function widgetopts_widgets_footer_additional_script()
272 {
273 ?>
274 <script>
275 (function() {
276 /*widget option search option function*/
277 function widgetopts_seach_button_function(e) {
278 let current_parent = e.target.closest('.extended-widget-opts-parent-option');
279 let current_select = current_parent.querySelector('.extended-widget-opts-select2-dropdown');
280 current_select.classList.add('select2-hidden-accessible');
281 current_parent.querySelector('.select2-container').classList.remove('widgetopts-is-hidden');
282
283 jQuery(current_parent).find('.multiselect-native-select .btn-group').addClass('hide');
284 jQuery(this).css({
285 "background-color": "#3D434A",
286 color: "#fff"
287 });
288
289 jQuery(this).parent().find('.widgetopts-dropdown-option-btn').css({
290 "background-color": "#fff",
291 color: "#777A80"
292 });
293 }
294
295 jQuery(document).on('click', '.widgetopts-search-option-btn', widgetopts_seach_button_function);
296
297 // let search_btns = document.getElementsByClassName('widgetopts-search-option-btn');
298 // for (let i = 0; i < search_btns.length; i++) {
299 // search_btns[i].addEventListener('click', widgetopts_seach_button_function, false);
300 // } /*end of widget option search option function*/
301
302 /*widget option dropdown option function*/
303 function widgetopts_dropdown_button_function(e) {
304 let current_parent = e.target.closest('.extended-widget-opts-parent-option');
305 let current_select = current_parent.querySelector('.extended-widget-opts-select2-dropdown');
306 current_select.classList.remove('select2-hidden-accessible');
307 current_parent.querySelector('.select2-container').classList.add('widgetopts-is-hidden');
308
309 jQuery(this).css({
310 "background-color": "#3D434A",
311 color: "#fff"
312 });
313
314 jQuery(this).parent().find('.widgetopts-search-option-btn').css({
315 "background-color": "#fff",
316 color: "#777A80"
317 });
318
319 if (jQuery(current_parent).find('.multiselect-native-select').length > 0) {
320 jQuery(current_parent).find('.multiselect-native-select .btn-group').removeClass('hide').find('.multiselect-container.dropdown-menu').removeClass('show');
321 } else {
322 let spinner = '<span class="spinner multiple-spinner" style="visibility: visible; float: none; display: inline-block; vertical-align: bottom;"></span>';
323 jQuery(e.target).parent().append(spinner);
324 jQuery(current_select).multiselect({
325 onInitialized: function(select, container) {
326 setTimeout(function() {
327 jQuery('.multiple-spinner').remove();
328 }, 500);
329 },
330 onChange: function(option, checked, select) {
331 jQuery(option).parents('.extended-widget-opts-parent-option').children('div:nth-child(1)').append(spinner);
332 setTimeout(function() {
333 jQuery('.multiple-spinner').remove();
334 }, 500);
335 },
336 buttonText: () => 'Click to add more',
337 keepOrder: true
338 });
339 }
340 }
341
342 jQuery(document).on('click', '.widgetopts-dropdown-option-btn', widgetopts_dropdown_button_function);
343
344 // let drop_btns = document.getElementsByClassName('widgetopts-dropdown-option-btn');
345 // for (let i = 0; i < drop_btns.length; i++) {
346 // drop_btns[i].addEventListener('click', widgetopts_dropdown_button_function, false);
347 // } /*end of widget option dropdown option function*/
348
349 jQuery(document).on('click', '.multiselect-native-select .multiselect.dropdown-toggle', function() {
350 jQuery(this).parent().find('.multiselect-container.dropdown-menu').each(function() {
351 if (jQuery(this).hasClass('show')) {
352 jQuery(this).removeClass('show');
353 } else {
354 jQuery(this).addClass('show');
355 }
356 });
357
358 });
359 })();
360 </script>
361 <?php }
362 add_action('admin_footer-widgets.php', 'widgetopts_widgets_footer_additional_script', 999);
363 }
364 ?>