API
1 week ago
DefaultOptions
2 years ago
PagesFields
4 months ago
SettingsFields
4 months ago
Announcement.php
1 week ago
Assets.php
1 week ago
Main.php
1 year ago
Page.php
1 week ago
PostType.php
2 years ago
Assets.php
76 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin assets. |
| 4 | * |
| 5 | * @package ShopPress |
| 6 | */ |
| 7 | |
| 8 | namespace ShopPress\Admin; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | class Assets { |
| 13 | /** |
| 14 | * Init. |
| 15 | * |
| 16 | * @since 1.2.0 |
| 17 | */ |
| 18 | public static function init() { |
| 19 | add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * enqueue scripts. |
| 24 | * |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | public static function enqueue_scripts() { |
| 28 | $screen = get_current_screen(); |
| 29 | if ( ! $screen || 'toplevel_page_shoppress' !== $screen->id ) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | wp_enqueue_media(); |
| 34 | |
| 35 | $script_path = SHOPPRESS_PATH . 'build/index.js'; |
| 36 | $script_asset_path = SHOPPRESS_PATH . 'build/index.asset.php'; |
| 37 | $script_asset = file_exists( $script_asset_path ) |
| 38 | ? require $script_asset_path |
| 39 | : array( |
| 40 | 'dependencies' => array( 'wp-element', 'wp-i18n' ), |
| 41 | 'version' => filemtime( $script_path ), |
| 42 | ); |
| 43 | $script_url = SHOPPRESS_URL . 'build/index.js'; |
| 44 | |
| 45 | wp_enqueue_script( 'sp-admin', $script_url, $script_asset['dependencies'], $script_asset['version'], true ); |
| 46 | |
| 47 | $shoppress_license = get_option( 'shoppress_license' ); |
| 48 | |
| 49 | wp_localize_script( |
| 50 | 'sp-admin', |
| 51 | 'shoppressOptions', |
| 52 | array( |
| 53 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| 54 | 'url' => esc_url_raw( rest_url() ), |
| 55 | 'admin_url' => esc_url_raw( get_admin_url() ), |
| 56 | 'is_pro' => is_active_shoppress_pro(), |
| 57 | 'is_elementor' => did_action( 'elementor/loaded' ), |
| 58 | 'license_key' => isset( $shoppress_license['license']['purchase_code'] ) && ! empty( $shoppress_license['license']['purchase_code'] ) ? $shoppress_license['license']['purchase_code'] : '', |
| 59 | 'version' => SHOPPRESS_VERSION, |
| 60 | ) |
| 61 | ); |
| 62 | |
| 63 | wp_set_script_translations( |
| 64 | 'sp-admin', |
| 65 | 'shop-press', |
| 66 | SHOPPRESS_PATH . 'languages' |
| 67 | ); |
| 68 | |
| 69 | wp_enqueue_style( 'sp-admin' ); |
| 70 | |
| 71 | if ( is_rtl() ) { |
| 72 | wp_enqueue_style( 'sp-admin-rtl' ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 |