builders
2 years ago
privacy
2 years ago
class-yit-ajax.php
2 years ago
class-yit-assets.php
2 years ago
class-yit-cpt-unlimited.php
5 years ago
class-yit-gradients.php
2 years ago
class-yit-help-desk.php
2 years ago
class-yit-icons.php
2 years ago
class-yit-metabox.php
2 years ago
class-yit-plugin-common.php
5 years ago
class-yit-plugin-licence.php
2 years ago
class-yit-plugin-panel-woocommerce.php
1 year ago
class-yit-plugin-panel.php
1 year ago
class-yit-plugin-subpanel.php
2 years ago
class-yit-pointers.php
2 years ago
class-yit-theme-licence.php
2 years ago
class-yit-upgrade.php
5 years ago
class-yit-video.php
5 years ago
class-yith-bh-onboarding.php
3 years ago
class-yith-dashboard.php
4 years ago
class-yith-debug.php
2 years ago
class-yith-external-services.php
1 year ago
class-yith-post-type-admin.php
2 years ago
class-yith-system-status.php
1 year ago
class-yit-assets.php
289 lines
| 1 | <?php |
| 2 | /** |
| 3 | * YITH Assets Class. Assets Handler. |
| 4 | * |
| 5 | * @class YIT_Assets |
| 6 | * @package YITH\PluginFramework\Classes |
| 7 | * @since 3.0.0 |
| 8 | */ |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 11 | |
| 12 | if ( ! class_exists( 'YIT_Assets' ) ) { |
| 13 | /** |
| 14 | * YIT_Assets class. |
| 15 | * |
| 16 | * @author YITH <plugins@yithemes.com> |
| 17 | */ |
| 18 | class YIT_Assets { |
| 19 | /** |
| 20 | * The framework version |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | public $version = '1.0.0'; |
| 25 | |
| 26 | /** |
| 27 | * The single instance of the class. |
| 28 | * |
| 29 | * @var YIT_Assets |
| 30 | */ |
| 31 | private static $instance; |
| 32 | |
| 33 | /** |
| 34 | * Singleton implementation. |
| 35 | * |
| 36 | * @return YIT_Assets |
| 37 | */ |
| 38 | public static function instance() { |
| 39 | return ! is_null( self::$instance ) ? self::$instance : self::$instance = new self(); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * YIT_Assets constructor. |
| 44 | */ |
| 45 | private function __construct() { |
| 46 | $this->version = yith_plugin_fw_get_version(); |
| 47 | add_action( 'init', array( $this, 'register_common_scripts' ) ); |
| 48 | add_action( 'elementor/editor/before_enqueue_styles', array( $this, 'register_common_scripts' ) ); |
| 49 | |
| 50 | add_action( 'admin_enqueue_scripts', array( $this, 'register_styles_and_scripts' ) ); |
| 51 | |
| 52 | add_action( 'init', array( $this, 'register_lapilli_ui_scripts' ) ); |
| 53 | add_action( 'should_load_block_editor_scripts_and_styles', array( $this, 'should_load_block_editor_scripts_and_styles' ), 10 ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Register common scripts |
| 58 | */ |
| 59 | public function register_common_scripts() { |
| 60 | wp_register_style( 'yith-plugin-fw-icon-font', YIT_CORE_PLUGIN_URL . '/assets/css/yith-icon.css', array(), $this->version ); |
| 61 | wp_register_style( 'yith-plugin-fw-elementor', YIT_CORE_PLUGIN_URL . '/assets/css/elementor.css', array(), $this->version ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Register Lapilli UI scripts |
| 66 | */ |
| 67 | public function register_lapilli_ui_scripts() { |
| 68 | $base_url = YIT_CORE_PLUGIN_URL . '/dist/lapilli-ui/'; |
| 69 | $base_path = YIT_CORE_PLUGIN_PATH . '/dist/lapilli-ui/'; |
| 70 | $packages = array( |
| 71 | 'lapilli-ui-block-editor' => 'block-editor', |
| 72 | 'lapilli-ui-components' => 'components', |
| 73 | 'lapilli-ui-styles' => 'styles', |
| 74 | 'lapilli-ui-date' => 'date', |
| 75 | ); |
| 76 | |
| 77 | foreach ( $packages as $handle => $package ) { |
| 78 | $asset_file = $base_path . $package . '/index.asset.php'; |
| 79 | |
| 80 | if ( file_exists( $asset_file ) ) { |
| 81 | $script_asset = include $asset_file; |
| 82 | $dependencies = $script_asset['dependencies'] ?? array(); |
| 83 | $version = $script_asset['version'] ?? '1.0.0'; |
| 84 | |
| 85 | $script = $base_url . $package . '/index.js'; |
| 86 | |
| 87 | if ( 'lapilli-ui-date' === $handle ) { |
| 88 | $dependencies[] = 'wp-date'; |
| 89 | } |
| 90 | |
| 91 | wp_register_script( $handle, $script, $dependencies, $version, true ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | $locale_options = array( |
| 96 | 'options' => array( |
| 97 | 'weekStartsOn' => (int) get_option( 'start_of_week', 0 ), |
| 98 | ), |
| 99 | ); |
| 100 | |
| 101 | $date_formats = array( |
| 102 | 'year' => 'Y', |
| 103 | 'month' => 'F', |
| 104 | 'dayOfMonth' => 'j', |
| 105 | 'monthShort' => 'M', |
| 106 | 'weekday' => 'l', |
| 107 | 'weekdayShort' => 'D', |
| 108 | 'fullDate' => get_option( 'date_format', 'F j, Y' ), |
| 109 | 'inputDate' => 'Y-m-d', |
| 110 | 'monthAndDate' => 'F j', |
| 111 | 'monthAndYear' => 'F Y', |
| 112 | ); |
| 113 | |
| 114 | wp_add_inline_script( |
| 115 | 'lapilli-ui-date', |
| 116 | 'lapilliUI.date.setLocale( ' . wp_json_encode( $locale_options ) . ' ); |
| 117 | lapilliUI.date.setDateFormats( ' . wp_json_encode( $date_formats ) . ' ); |
| 118 | lapilliUI.date.setFormatDate( wp.date.format );' |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Should load block editor scripts and styles. |
| 124 | * |
| 125 | * @param bool $should_load Should load flag. |
| 126 | * |
| 127 | * @return bool |
| 128 | */ |
| 129 | public function should_load_block_editor_scripts_and_styles( $should_load ) { |
| 130 | if ( ! $should_load ) { |
| 131 | $should_load = wp_script_is( 'lapilli-ui-block-editor', 'enqueued' ); |
| 132 | } |
| 133 | |
| 134 | return $should_load; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Register styles and scripts |
| 139 | */ |
| 140 | public function register_styles_and_scripts() { |
| 141 | global $wp_scripts, $woocommerce, $wp_version, $pagenow; |
| 142 | |
| 143 | $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false; |
| 144 | $screen_id = $screen && is_a( $screen, 'WP_Screen' ) ? $screen->id : ''; |
| 145 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 146 | |
| 147 | // Register scripts. |
| 148 | wp_register_script( 'yith-ui', YIT_CORE_PLUGIN_URL . '/assets/js/yith-ui' . $suffix . '.js', array( 'jquery' ), $this->version, true ); |
| 149 | wp_register_script( 'yith-colorpicker', YIT_CORE_PLUGIN_URL . '/assets/js/yith-colorpicker.min.js', array( 'jquery', 'wp-color-picker' ), '3.0.0', true ); |
| 150 | wp_register_script( 'yith-plugin-fw-fields', YIT_CORE_PLUGIN_URL . '/assets/js/yith-fields' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'yith-colorpicker', 'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-tiptip', 'yith-ui' ), $this->version, true ); |
| 151 | wp_register_script( 'yith-date-format', YIT_CORE_PLUGIN_URL . '/assets/js/yith-date-format' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), $this->version, true ); |
| 152 | |
| 153 | wp_register_script( 'yit-metabox', YIT_CORE_PLUGIN_URL . '/assets/js/metabox' . $suffix . '.js', array( 'jquery', 'wp-color-picker', 'yith-plugin-fw-fields', 'yith-ui' ), $this->version, true ); |
| 154 | wp_register_script( 'yit-plugin-panel', YIT_CORE_PLUGIN_URL . '/assets/js/yit-plugin-panel' . $suffix . '.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-sortable', 'yith-plugin-fw-fields', 'yith-ui', 'utils', 'jquery-blockui' ), $this->version, true ); |
| 155 | wp_register_script( 'colorbox', YIT_CORE_PLUGIN_URL . '/assets/js/jquery.colorbox' . $suffix . '.js', array( 'jquery' ), '1.6.3', true ); |
| 156 | wp_register_script( 'yith_how_to', YIT_CORE_PLUGIN_URL . '/assets/js/how-to' . $suffix . '.js', array( 'jquery' ), $this->version, true ); |
| 157 | wp_register_script( 'yith-plugin-fw-wp-pages', YIT_CORE_PLUGIN_URL . '/assets/js/wp-pages' . $suffix . '.js', array( 'jquery' ), $this->version, false ); |
| 158 | wp_register_script( 'yith-bh-onboarding', YIT_CORE_PLUGIN_URL . '/assets/js/yith-bh-onboarding' . $suffix . '.js', array( 'jquery', 'yit-plugin-panel', 'yith-plugin-fw-fields', 'jquery-blockui' ), $this->version, true ); |
| 159 | wp_register_script( 'yith-plugin-fw-welcome-modal', YIT_CORE_PLUGIN_URL . '/assets/js/welcome-modal' . $suffix . '.js', array( 'jquery', 'wp-util', 'yith-ui' ), $this->version, true ); |
| 160 | |
| 161 | // Register styles. |
| 162 | wp_register_style( 'yith-plugin-ui', YIT_CORE_PLUGIN_URL . '/assets/css/yith-plugin-ui.css', array( 'yith-plugin-fw-icon-font' ), $this->version ); |
| 163 | wp_register_style( 'yit-plugin-style', YIT_CORE_PLUGIN_URL . '/assets/css/yit-plugin-panel.css', array( 'yith-plugin-ui' ), $this->version ); // TODO: to remove. Deprecated since 4.0.0! |
| 164 | wp_register_style( 'yith-plugin-panel', YIT_CORE_PLUGIN_URL . '/assets/css/yith-plugin-panel.css', array( 'yith-plugin-ui' ), $this->version ); |
| 165 | wp_register_style( 'jquery-ui-style', YIT_CORE_PLUGIN_URL . '/assets/css/jquery-ui/jquery-ui.min.css', array(), '1.11.4' ); |
| 166 | wp_register_style( 'colorbox', YIT_CORE_PLUGIN_URL . '/assets/css/colorbox.css', array(), $this->version ); |
| 167 | wp_register_style( 'yit-upgrade-to-pro', YIT_CORE_PLUGIN_URL . '/assets/css/yit-upgrade-to-pro.css', array( 'colorbox' ), $this->version ); |
| 168 | wp_register_style( 'yit-plugin-metaboxes', YIT_CORE_PLUGIN_URL . '/assets/css/metaboxes.css', array( 'yith-plugin-ui' ), $this->version ); |
| 169 | wp_register_style( 'yith-plugin-fw-fields', YIT_CORE_PLUGIN_URL . '/assets/css/yith-fields.css', array( 'yith-plugin-ui' ), $this->version ); |
| 170 | wp_register_style( 'yith-bh-onboarding', YIT_CORE_PLUGIN_URL . '/assets/css/yith-bh-onboarding.css', array( 'yith-plugin-ui', 'yith-plugin-fw-fields' ), $this->version ); |
| 171 | wp_register_style( 'yith-plugin-fw-welcome-modal', YIT_CORE_PLUGIN_URL . '/assets/css/welcome-modal.css', array(), $this->version ); |
| 172 | |
| 173 | $wc_version_suffix = ''; |
| 174 | if ( function_exists( 'WC' ) || ! empty( $woocommerce ) ) { |
| 175 | $woocommerce_version = function_exists( 'WC' ) ? WC()->version : $woocommerce->version; |
| 176 | $wc_version_suffix = version_compare( $woocommerce_version, '3.0.0', '>=' ) ? '' : '-wc-2.6'; |
| 177 | |
| 178 | wp_register_style( 'woocommerce_admin_styles', $woocommerce->plugin_url() . '/assets/css/admin.css', array(), $woocommerce_version ); |
| 179 | } else { |
| 180 | wp_register_script( 'jquery-tiptip', YIT_CORE_PLUGIN_URL . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), '1.3', true ); |
| 181 | wp_register_script( 'select2', YIT_CORE_PLUGIN_URL . '/assets/js/select2/select2.min.js', array( 'jquery' ), '4.0.3', true ); |
| 182 | wp_register_style( 'yith-select2-no-wc', YIT_CORE_PLUGIN_URL . '/assets/css/yith-select2-no-wc.css', false, $this->version ); |
| 183 | } |
| 184 | |
| 185 | wp_register_script( 'yith-enhanced-select', YIT_CORE_PLUGIN_URL . '/assets/js/yith-enhanced-select' . $wc_version_suffix . $suffix . '.js', array( 'jquery', 'select2' ), $this->version, true ); |
| 186 | wp_localize_script( |
| 187 | 'yith-enhanced-select', |
| 188 | 'yith_framework_enhanced_select_params', |
| 189 | array( |
| 190 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 191 | 'search_posts_nonce' => wp_create_nonce( 'search-posts' ), |
| 192 | 'search_terms_nonce' => wp_create_nonce( 'search-terms' ), |
| 193 | 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), |
| 194 | 'search_pages_nonce' => wp_create_nonce( 'search-pages' ), |
| 195 | 'i18n' => array( |
| 196 | 'no_matches' => _x( 'No matches found', 'Enhanced select', 'yith-plugin-fw' ), |
| 197 | 'input_too_short_1' => _x( 'Please enter 1 or more characters', 'Enhanced select', 'yith-plugin-fw' ), |
| 198 | // translators: %s is the number of characters. |
| 199 | 'input_too_short_n' => _x( 'Please enter %s or more characters', 'Enhanced select', 'yith-plugin-fw' ), |
| 200 | 'searching' => _x( 'Searching…', 'Enhanced select', 'yith-plugin-fw' ), |
| 201 | ), |
| 202 | ) |
| 203 | ); |
| 204 | |
| 205 | wp_localize_script( |
| 206 | 'yith-plugin-fw-fields', |
| 207 | 'yith_framework_fw_fields', |
| 208 | array( |
| 209 | 'admin_url' => admin_url( 'admin.php' ), |
| 210 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 211 | 'i18n' => array( |
| 212 | 'error' => _x( 'Error', 'Title', 'yith-plugin-fw' ), |
| 213 | 'noFileError' => __( 'No file provided.', 'yith-plugin-fw' ), |
| 214 | 'cannotDropError' => __( 'You cannot drop files here.', 'yith-plugin-fw' ), |
| 215 | ), |
| 216 | ) |
| 217 | ); |
| 218 | |
| 219 | wp_localize_script( |
| 220 | 'yith-ui', |
| 221 | 'yith_plugin_fw_ui', |
| 222 | array( |
| 223 | 'i18n' => array( |
| 224 | 'confirm' => _x( 'Confirm', 'Button text', 'yith-plugin-fw' ), |
| 225 | 'cancel' => _x( 'Cancel', 'Button text', 'yith-plugin-fw' ), |
| 226 | ), |
| 227 | ) |
| 228 | ); |
| 229 | |
| 230 | wp_localize_script( |
| 231 | 'yith-plugin-fw-wp-pages', |
| 232 | 'yith_plugin_fw_wp_pages', |
| 233 | array( |
| 234 | 'bulk_delete_confirmation_enabled' => ! ! apply_filters( "yith_plugin_fw_{$screen_id}_bulk_delete_confirmation_enabled", in_array( $pagenow, array( 'edit.php', 'edit-tags.php' ), true ) ), |
| 235 | 'i18n' => array( |
| 236 | 'bulk_trash_confirm_title' => __( 'Confirm trash', 'yith-plugin-fw' ), |
| 237 | 'bulk_trash_confirm_message' => __( 'Are you sure you want to trash the selected items?', 'yith-plugin-fw' ), |
| 238 | 'bulk_trash_confirm_button' => _x( 'Yes, move to trash', 'Trash confirmation action', 'yith-plugin-fw' ), |
| 239 | 'bulk_trash_cancel_button' => __( 'No', 'yith-plugin-fw' ), |
| 240 | 'bulk_delete_confirm_title' => __( 'Confirm delete', 'yith-plugin-fw' ), |
| 241 | 'bulk_delete_confirm_message' => __( 'Are you sure you want to delete the selected items?', 'yith-plugin-fw' ) . '<br /><br />' . __( 'This action cannot be undone and you will not be able to recover this data.', 'yith-plugin-fw' ), |
| 242 | 'bulk_delete_confirm_button' => _x( 'Yes, delete', 'Delete confirmation action', 'yith-plugin-fw' ), |
| 243 | 'bulk_delete_cancel_button' => __( 'No', 'yith-plugin-fw' ), |
| 244 | ), |
| 245 | ) |
| 246 | ); |
| 247 | |
| 248 | wp_localize_script( |
| 249 | 'yith-bh-onboarding', |
| 250 | 'yith_bh_onboarding', |
| 251 | array( |
| 252 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 253 | ) |
| 254 | ); |
| 255 | |
| 256 | wp_localize_script( |
| 257 | 'yit-plugin-panel', |
| 258 | 'yithFwPluginPanel', |
| 259 | array( |
| 260 | 'i18n' => array( |
| 261 | 'resetConfirmTitle' => __( 'Are you sure?', 'yith-plugin-fw' ), |
| 262 | 'resetConfirmMessage' => __( 'If you continue with this action, you will reset all options in this page.', 'yith-plugin-fw' ), |
| 263 | ), |
| 264 | ) |
| 265 | ); |
| 266 | |
| 267 | // Localize color-picker to avoid issues with WordPress 5.5. |
| 268 | if ( version_compare( $wp_version, '5.5-RC', '>=' ) ) { |
| 269 | wp_localize_script( |
| 270 | 'yith-colorpicker', |
| 271 | 'wpColorPickerL10n', |
| 272 | array( |
| 273 | 'clear' => __( 'Clear' ), |
| 274 | 'clearAriaLabel' => __( 'Clear color' ), |
| 275 | 'defaultString' => __( 'Default' ), |
| 276 | 'defaultAriaLabel' => __( 'Select default color' ), |
| 277 | 'pick' => __( 'Select Color' ), |
| 278 | 'defaultLabel' => __( 'Color value' ), |
| 279 | ) |
| 280 | ); |
| 281 | } |
| 282 | |
| 283 | wp_enqueue_style( 'yith-plugin-fw-admin', YIT_CORE_PLUGIN_URL . '/assets/css/admin.css', array(), $this->version ); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | YIT_Assets::instance(); |
| 289 |