PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / elementor / wp-one-package / src / Admin / Components / Assets.php

Assets.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at vendor/elementor/wp-one-package/src/Admin/Components/Assets.php

126 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ElementorOne\Admin\Components;
4
5 use ElementorOne\Admin\Helpers\Utils;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Class Assets
13 * Handles script and style enqueuing for the admin area
14 */
15 class Assets {
16
17 /**
18 * Instance
19 * @var Assets|null
20 */
21 private static ?Assets $instance = null;
22
23 /**
24 * Get instance
25 * @return Assets|null
26 */
27 public static function instance(): ?Assets {
28 if ( ! self::$instance ) {
29 self::$instance = new self();
30 }
31 return self::$instance;
32 }
33
34 /**
35 * Get admin page
36 * @return string
37 */
38 private function get_admin_page(): string {
39 return Utils::get_one_connect()->get_config( 'admin_page' );
40 }
41
42 /**
43 * Enqueue scripts
44 * @param string $hook
45 * @return void
46 */
47 public function enqueue_scripts( $hook ) {
48 $package_version = Utils::get_latest_package_version();
49
50 // Enqueue fonts
51 wp_enqueue_style(
52 'elementor-one-admin-fonts',
53 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap',
54 [],
55 '1.0.0'
56 );
57
58 // Enqueue common assets
59 $this->enqueue_common_assets( $package_version );
60
61 // Enqueue app assets only on Elementor Home admin page
62 if ( "toplevel_page_{$this->get_admin_page()}" === $hook ) {
63 $this->enqueue_app_assets( $package_version );
64 }
65 }
66
67 /**
68 * Get plugin env
69 * @return string
70 */
71 private static function get_plugin_env(): string {
72 return apply_filters( 'elementor_one/package_env', 'production' );
73 }
74
75 /**
76 * Enqueue app assets
77 * @param string $package_version
78 * @return void
79 */
80 private function enqueue_app_assets( string $package_version ) {
81 wp_enqueue_script( 'elementor-one-admin', ELEMENTOR_ONE_CLIENT_APP_URL, [], $package_version, true );
82 }
83
84 /**
85 * Enqueue common assets
86 * @param string $package_version
87 * @return void
88 */
89 private function enqueue_common_assets( string $package_version ) {
90 // Load the asset file to get dependencies and version
91 $asset_file = ELEMENTOR_ONE_ASSETS_PATH . 'common.asset.php';
92 $asset = file_exists( $asset_file ) ? include $asset_file : [
93 'dependencies' => [],
94 'version' => $package_version,
95 ];
96
97 wp_enqueue_script( 'elementor-one-admin-common', ELEMENTOR_ONE_ASSETS_URL . 'common.js', $asset['dependencies'], $asset['version'], true );
98 wp_enqueue_style( 'elementor-one-admin-common', ELEMENTOR_ONE_ASSETS_URL . 'common.css', [], $package_version );
99
100 wp_add_inline_script(
101 'elementor-one-admin-common',
102 'window.elementorOneSettingsData = ' . wp_json_encode( [
103 'wpRestNonce' => wp_create_nonce( 'wp_rest' ),
104 'wpRestUrl' => rest_url(),
105 'pluginEnv' => self::get_plugin_env(),
106 'packageVersion' => Utils::get_latest_package_version(),
107 'canUserManageOptions' => current_user_can( 'manage_options' ),
108 'elementorNewPostNonce' => wp_create_nonce( 'elementor_action_new_post' ),
109 'elementorSiteSettingsRedirectNonce' => wp_create_nonce( 'elementor_action_site_settings_redirect' ),
110 'elementorEditSiteNonce' => wp_create_nonce( 'elementor_action_edit_website' ),
111 'manageSiteOverviewRedirectNonce' => wp_create_nonce( 'manage_site_overview_redirect' ),
112 'shareUsageData' => 'yes' === Utils::get_one_connect()->data()->get_share_usage_data(),
113 'assetsUIRootUrl' => ELEMENTOR_ONE_UI_ASSETS_ROOT_URL,
114 ] ) . ';'
115 );
116 }
117
118 /**
119 * Assets constructor
120 * @return void
121 */
122 private function __construct() {
123 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
124 }
125 }
126