admin
4 years ago
pagebuilders
4 years ago
widgets
4 years ago
ajax-functions.php
8 years ago
extras.php
4 years ago
install.php
4 years ago
scripts.php
4 years ago
transient.php
8 years ago
scripts.php
169 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Scripts |
| 4 | * |
| 5 | * @copyright Copyright (c) 2016, Jeffrey Carandang |
| 6 | * @since 3.0 |
| 7 | */ |
| 8 | |
| 9 | // Exit if accessed directly |
| 10 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 11 | |
| 12 | /** |
| 13 | * Load Scripts |
| 14 | * |
| 15 | * Enqueues the required scripts. |
| 16 | * |
| 17 | * @since 3.0 |
| 18 | * @return void |
| 19 | */ |
| 20 | |
| 21 | function widgetopts_load_scripts(){ |
| 22 | $css_dir = WIDGETOPTS_PLUGIN_URL . 'assets/css/'; |
| 23 | wp_enqueue_style( 'widgetopts-styles', $css_dir . 'widget-options.css' , array(), null ); |
| 24 | } |
| 25 | add_action( 'wp_enqueue_scripts', 'widgetopts_load_scripts' ); |
| 26 | add_action( 'customize_controls_enqueue_scripts', 'widgetopts_load_scripts' ); |
| 27 | |
| 28 | /** |
| 29 | * Load Admin Scripts |
| 30 | * |
| 31 | * Enqueues the required admin scripts. |
| 32 | * |
| 33 | * @since 3.0 |
| 34 | * @global $widget_options |
| 35 | * @param string $hook Page hook |
| 36 | * @return void |
| 37 | */ |
| 38 | if( !function_exists( 'widgetopts_load_admin_scripts' ) ): |
| 39 | function widgetopts_load_admin_scripts( $hook ) { |
| 40 | global $widget_options; |
| 41 | |
| 42 | $js_dir = WIDGETOPTS_PLUGIN_URL . 'assets/js/'; |
| 43 | $css_dir = WIDGETOPTS_PLUGIN_URL . 'assets/css/'; |
| 44 | |
| 45 | // Use minified libraries if SCRIPT_DEBUG is turned off |
| 46 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 47 | |
| 48 | wp_enqueue_style( 'widgetopts-admin-styles', $css_dir . 'admin.css' , array(), null ); |
| 49 | |
| 50 | if( !in_array( $hook, apply_filters( 'widgetopts_exclude_jqueryui', array( 'toplevel_page_et_divi_options', 'toplevel_page_wpcf7', 'edit.php' ) ) ) ){ |
| 51 | wp_enqueue_style( 'jquery-ui' ); |
| 52 | } |
| 53 | |
| 54 | if( in_array( $hook, apply_filters( 'widgetopts_load_liveFilter_scripts', array( 'widgets.php' ) ) ) ){ |
| 55 | wp_enqueue_script( |
| 56 | 'jquery-liveFilter', |
| 57 | plugins_url( 'assets/js/jquery.liveFilter.js' , dirname(__FILE__) ), |
| 58 | array( 'jquery' ), |
| 59 | '', |
| 60 | true |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | wp_enqueue_script( |
| 65 | 'jquery-widgetopts-option-tabs', |
| 66 | plugins_url( 'assets/js/wpWidgetOpts.js' , dirname(__FILE__) ), |
| 67 | array( 'jquery', 'jquery-ui-core', 'jquery-ui-tabs', 'jquery-ui-datepicker'), |
| 68 | '', |
| 69 | true |
| 70 | ); |
| 71 | |
| 72 | $form = '<div id="widgetopts-widgets-chooser"> |
| 73 | <label class="screen-reader-text" for="widgetopts-search-chooser">'. __( 'Search Sidebar', 'widget-options' ) .'</label> |
| 74 | <input type="text" id="widgetopts-search-chooser" class="widgetopts-widgets-search" placeholder="'. __( 'Search sidebar…', 'widget-options' ) .'" /> |
| 75 | <div class="widgetopts-search-icon" aria-hidden="true"></div> |
| 76 | <button type="button" class="widgetopts-clear-results"><span class="screen-reader-text">'. __( 'Clear Results', 'widget-options' ) .'</span></button> |
| 77 | <p class="screen-reader-text" id="widgetopts-chooser-desc">'. __( 'The search results will be updated as you type.', 'widget-options' ) .'</p> |
| 78 | </div>'; |
| 79 | |
| 80 | $btn_controls = ''; |
| 81 | if( isset( $widget_options['move'] ) && 'activate' == $widget_options['move'] ){ |
| 82 | $btn_controls .= ' | <button type="button" class="button-link widgetopts-control" data-action="move">'. __( 'Move', 'widget-options' ) .'</button>'; |
| 83 | } |
| 84 | |
| 85 | $sidebaropts = ''; |
| 86 | if( isset( $widget_options['widget_area'] ) && 'activate' == $widget_options['widget_area'] ){ |
| 87 | $sidebaropts = '<div class="widgetopts-sidebaropts">'; |
| 88 | if( isset( $widget_options['settings']['widget_area'] ) && isset( $widget_options['settings']['widget_area']['remove'] ) && '1' == $widget_options['settings']['widget_area']['remove'] ){ |
| 89 | $sidebaropts .= '<a href="#" class="sidebaropts-clear"> |
| 90 | <span class="dashicons dashicons-warning"></span> '. __( 'Remove All Widgets', 'widget-options' ) .' |
| 91 | </a>'; |
| 92 | } |
| 93 | if( isset( $widget_options['settings']['widget_area'] ) && isset( $widget_options['settings']['widget_area']['backup'] ) && '1' == $widget_options['settings']['widget_area']['backup'] ){ |
| 94 | $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') ) .'"> |
| 95 | <span class="dashicons dashicons-download"></span> '. __( 'Download Backup', 'widget-options' ) .' |
| 96 | </a>'; |
| 97 | } |
| 98 | |
| 99 | if( isset( $widget_options['settings']['widget_area'] ) && isset( $widget_options['settings']['widget_area']['remove'] ) && '1' == $widget_options['settings']['widget_area']['remove'] ){ |
| 100 | $sidebaropts .= '<div class="sidebaropts-confirm"><p> |
| 101 | '. __( 'Are you sure you want to DELETE ALL widgets associated to __sidebar_opts__?', 'widget-options' ) .' |
| 102 | </p> |
| 103 | <button class="button">'. __( 'No', 'widget-options' ) .'</button> |
| 104 | <button class="button button-primary">'. __( 'Yes', 'widget-options' ) .'</button> |
| 105 | </div>'; |
| 106 | } |
| 107 | |
| 108 | $sidebaropts .= '</div>'; |
| 109 | } |
| 110 | |
| 111 | wp_localize_script( 'jquery-widgetopts-option-tabs', 'widgetopts10n', array( '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' ) )) ); |
| 112 | |
| 113 | if( in_array( $hook, apply_filters( 'widgetopts_load_settings_scripts', array( 'settings_page_widgetopts_plugin_settings' ) ) ) ){ |
| 114 | wp_register_script( |
| 115 | 'jquery-widgetopts-settings', |
| 116 | $js_dir .'settings'. $suffix .'.js', |
| 117 | array( 'jquery' ), |
| 118 | '', |
| 119 | true |
| 120 | ); |
| 121 | |
| 122 | $translation = array( |
| 123 | 'save_settings' => __( 'Save Settings', 'widget-options' ), |
| 124 | 'close_settings' => __( 'Close', 'widget-options' ), |
| 125 | 'show_settings' => __( 'Configure Settings', 'widget-options' ), |
| 126 | 'hide_settings' => __( 'Hide Settings', 'widget-options' ), |
| 127 | 'show_description' => __( 'Learn More', 'widget-options' ), |
| 128 | 'hide_description' => __( 'Hide Details', 'widget-options' ), |
| 129 | 'show_information' => __( 'Show Details', 'widget-options' ), |
| 130 | 'activate' => __( 'Enable', 'widget-options' ), |
| 131 | 'deactivate' => __( 'Disable', 'widget-options' ), |
| 132 | 'successful_save' => __( 'Settings saved successfully for %1$s.', 'widget-options' ), |
| 133 | 'deactivate_btn' => __( 'Deactivate License', 'widget-options' ), |
| 134 | 'activate_btn' => __( 'Activate License', 'widget-options' ), |
| 135 | 'status_valid' => __( 'Valid', 'widget-options' ), |
| 136 | 'status_invalid' => __( 'Invalid', 'widget-options' ), |
| 137 | ); |
| 138 | |
| 139 | wp_enqueue_script( 'jquery-widgetopts-settings' ); |
| 140 | wp_localize_script( 'jquery-widgetopts-settings', 'widgetopts', array( 'translation' => $translation, 'ajax_action' => 'widgetopts_ajax_settings', 'ajax_nonce' => wp_create_nonce( 'widgetopts-settings-nonce' ), ) ); |
| 141 | } |
| 142 | } |
| 143 | add_action( 'admin_enqueue_scripts', 'widgetopts_load_admin_scripts', 100 ); |
| 144 | endif; |
| 145 | |
| 146 | if( !function_exists( 'widgetopts_widgets_footer' ) ){ |
| 147 | function widgetopts_widgets_footer(){ |
| 148 | global $widget_options;?> |
| 149 | <div class="widgetsopts-chooser" style="display:none;"> |
| 150 | <?php if( isset( $widget_options['search'] ) && 'activate' == $widget_options['search'] ): ?> |
| 151 | <div id="widgetopts-widgets-chooser"> |
| 152 | <label class="screen-reader-text" for="widgetopts-search-chooser"><?php _e( 'Search Sidebar', 'widget-options' );?></label> |
| 153 | <input type="text" id="widgetsopts-widgets-search" class="widgetopts-widgets-search widgetsopts-widgets-search" placeholder="Search sidebar…"> |
| 154 | <div class="widgetopts-search-icon" aria-hidden="true"></div> |
| 155 | <button type="button" class="widgetopts-clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results', 'widget-options' );?></span></button> |
| 156 | <p class="screen-reader-text" id="widgetopts-chooser-desc"><?php _e( 'The search results will be updated as you type.', 'widget-options' );?></p> |
| 157 | </div> |
| 158 | <?php endif; ?> |
| 159 | <ul class="widgetopts-chooser-sidebars"></ul> |
| 160 | <div class="widgetsopts-chooser-actions"> |
| 161 | <button class="button widgetsopts-chooser-cancel"><?php _e( 'Cancel', 'widget-options' ); ?></button> |
| 162 | <button class="button button-primary widgetopts-chooser-action"><span><?php _e( 'Move', 'widget-options' ); ?></span> <?php _e( 'Widget', 'widget-options' ); ?></button> |
| 163 | </div> |
| 164 | </div> |
| 165 | <?php } |
| 166 | add_action( 'admin_footer-widgets.php', 'widgetopts_widgets_footer' ); |
| 167 | } |
| 168 | ?> |
| 169 |