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