PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.5
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.5
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
345 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'))))) {
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')))) {
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 }
195 if (in_array($hook, apply_filters('widgetopts_load_settings_scripts', array('settings_page_widgetopts_plugin_settings')))) {
196 wp_register_script(
197 'jquery-widgetopts-settings',
198 $js_dir . 'settings' . $suffix . '.js',
199 array('jquery'),
200 WIDGETOPTS_VERSION,
201 ($is_6_3_and_above ? $in_footer_args : true)
202 );
203
204 $translation = array(
205 'save_settings' => __('Save Settings', 'widget-options'),
206 'close_settings' => __('Close', 'widget-options'),
207 'show_settings' => __('Configure Settings', 'widget-options'),
208 'hide_settings' => __('Hide Settings', 'widget-options'),
209 'show_description' => __('Learn More', 'widget-options'),
210 'hide_description' => __('Hide Details', 'widget-options'),
211 'show_information' => __('Show Details', 'widget-options'),
212 'activate' => __('Enable', 'widget-options'),
213 'deactivate' => __('Disable', 'widget-options'),
214 'successful_save' => __('Settings saved successfully for %1$s.', 'widget-options'),
215 'deactivate_btn' => __('Deactivate License', 'widget-options'),
216 'activate_btn' => __('Activate License', 'widget-options'),
217 'status_valid' => __('Valid', 'widget-options'),
218 'status_invalid' => __('Invalid', 'widget-options'),
219 );
220
221 wp_enqueue_script('jquery-widgetopts-settings');
222 wp_localize_script('jquery-widgetopts-settings', 'widgetopts', array('translation' => $translation, 'ajax_action' => 'widgetopts_ajax_settings', 'ajax_nonce' => wp_create_nonce('widgetopts-settings-nonce'),));
223 }
224 }
225 add_action('admin_enqueue_scripts', 'widgetopts_load_admin_scripts', 100);
226 endif;
227
228 if (!function_exists('widgetopts_widgets_footer')) {
229 function widgetopts_widgets_footer()
230 {
231 global $widget_options; ?>
232 <div class="widgetsopts-chooser" style="display:none;">
233 <?php if (isset($widget_options['search']) && 'activate' == $widget_options['search']) : ?>
234 <div id="widgetopts-widgets-chooser">
235 <label class="screen-reader-text" for="widgetopts-search-chooser"><?php _e('Search Sidebar', 'widget-options'); ?></label>
236 <input type="text" id="widgetsopts-widgets-search" class="widgetopts-widgets-search widgetsopts-widgets-search" placeholder="Search sidebar…">
237 <div class="widgetopts-search-icon" aria-hidden="true"></div>
238 <button type="button" class="widgetopts-clear-results"><span class="screen-reader-text"><?php _e('Clear Results', 'widget-options'); ?></span></button>
239 <p class="screen-reader-text" id="widgetopts-chooser-desc"><?php _e('The search results will be updated as you type.', 'widget-options'); ?></p>
240 </div>
241 <?php endif; ?>
242 <ul class="widgetopts-chooser-sidebars"></ul>
243 <div class="widgetsopts-chooser-actions">
244 <button class="button widgetsopts-chooser-cancel"><?php _e('Cancel', 'widget-options'); ?></button>
245 <button class="button button-primary widgetopts-chooser-action"><span><?php _e('Move', 'widget-options'); ?></span> <?php _e('Widget', 'widget-options'); ?></button>
246 </div>
247 </div>
248 <?php }
249 add_action('admin_footer-widgets.php', 'widgetopts_widgets_footer');
250 }
251
252 if (!function_exists('widgetopts_widgets_footer_additional_script')) {
253 function widgetopts_widgets_footer_additional_script()
254 {
255 ?>
256 <script>
257 (function() {
258 /*widget option search option function*/
259 function widgetopts_seach_button_function(e) {
260 let current_parent = e.target.closest('.extended-widget-opts-parent-option');
261 let current_select = current_parent.querySelector('.extended-widget-opts-select2-dropdown');
262 current_select.classList.add('select2-hidden-accessible');
263 current_parent.querySelector('.select2-container').classList.remove('widgetopts-is-hidden');
264
265 jQuery(current_parent).find('.multiselect-native-select .btn-group').addClass('hide');
266 jQuery(this).css({
267 "background-color": "#3D434A",
268 color: "#fff"
269 });
270
271 jQuery(this).parent().find('.widgetopts-dropdown-option-btn').css({
272 "background-color": "#fff",
273 color: "#777A80"
274 });
275 }
276
277 jQuery(document).on('click', '.widgetopts-search-option-btn', widgetopts_seach_button_function);
278
279 // let search_btns = document.getElementsByClassName('widgetopts-search-option-btn');
280 // for (let i = 0; i < search_btns.length; i++) {
281 // search_btns[i].addEventListener('click', widgetopts_seach_button_function, false);
282 // } /*end of widget option search option function*/
283
284 /*widget option dropdown option function*/
285 function widgetopts_dropdown_button_function(e) {
286 let current_parent = e.target.closest('.extended-widget-opts-parent-option');
287 let current_select = current_parent.querySelector('.extended-widget-opts-select2-dropdown');
288 current_select.classList.remove('select2-hidden-accessible');
289 current_parent.querySelector('.select2-container').classList.add('widgetopts-is-hidden');
290
291 jQuery(this).css({
292 "background-color": "#3D434A",
293 color: "#fff"
294 });
295
296 jQuery(this).parent().find('.widgetopts-search-option-btn').css({
297 "background-color": "#fff",
298 color: "#777A80"
299 });
300
301 if (jQuery(current_parent).find('.multiselect-native-select').length > 0) {
302 jQuery(current_parent).find('.multiselect-native-select .btn-group').removeClass('hide').find('.multiselect-container.dropdown-menu').removeClass('show');
303 } else {
304 let spinner = '<span class="spinner multiple-spinner" style="visibility: visible; float: none; display: inline-block; vertical-align: bottom;"></span>';
305 jQuery(e.target).parent().append(spinner);
306 jQuery(current_select).multiselect({
307 onInitialized: function(select, container) {
308 setTimeout(function() {
309 jQuery('.multiple-spinner').remove();
310 }, 500);
311 },
312 onChange: function(option, checked, select) {
313 jQuery(option).parents('.extended-widget-opts-parent-option').children('div:nth-child(1)').append(spinner);
314 setTimeout(function() {
315 jQuery('.multiple-spinner').remove();
316 }, 500);
317 },
318 buttonText: () => 'Click to add more'
319 });
320 }
321 }
322
323 jQuery(document).on('click', '.widgetopts-dropdown-option-btn', widgetopts_dropdown_button_function);
324
325 // let drop_btns = document.getElementsByClassName('widgetopts-dropdown-option-btn');
326 // for (let i = 0; i < drop_btns.length; i++) {
327 // drop_btns[i].addEventListener('click', widgetopts_dropdown_button_function, false);
328 // } /*end of widget option dropdown option function*/
329
330 jQuery(document).on('click', '.multiselect-native-select .multiselect.dropdown-toggle', function() {
331 jQuery(this).parent().find('.multiselect-container.dropdown-menu').each(function() {
332 if (jQuery(this).hasClass('show')) {
333 jQuery(this).removeClass('show');
334 } else {
335 jQuery(this).addClass('show');
336 }
337 });
338
339 });
340 })();
341 </script>
342 <?php }
343 add_action('admin_footer-widgets.php', 'widgetopts_widgets_footer_additional_script', 999);
344 }
345 ?>