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