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