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