PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.0-dev4
Elementor Website Builder – more than just a page builder v3.22.0-dev4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / page-assets / loader.php

loader.php in Elementor Website Builder – more than just a page builder 3.22.0-dev4, at core/page-assets/loader.php

124 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Page_Assets;
3
4 use Elementor\Core\Base\Module;
5 use Elementor\Plugin;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly
9 }
10
11 /**
12 * Elementor assets loader.
13 *
14 * A class that is responsible for conditionally enqueuing styles and script assets that were pre-enabled.
15 *
16 * @since 3.3.0
17 */
18 class Loader extends Module {
19 private $assets;
20
21 public function get_name() {
22 return 'assets-loader';
23 }
24
25 private function init_assets() {
26 $this->assets = [
27 'styles' => [
28 'e-animations' => [
29 'src' => $this->get_css_assets_url( 'animations', 'assets/lib/animations/', true ),
30 'version' => ELEMENTOR_VERSION,
31 'dependencies' => [],
32 ],
33 ],
34 'scripts' => [],
35 ];
36 }
37
38 public function get_assets() {
39 if ( ! $this->assets ) {
40 $this->init_assets();
41 }
42
43 return $this->assets;
44 }
45
46 /**
47 * @param array $assets {
48 * @type array 'styles'
49 * @type array 'scripts'
50 * }
51 */
52 public function enable_assets( array $assets_data ) {
53 if ( ! $this->assets ) {
54 $this->init_assets();
55 }
56
57 foreach ( $assets_data as $assets_type => $assets_list ) {
58 foreach ( $assets_list as $asset_name ) {
59 $this->assets[ $assets_type ][ $asset_name ]['enabled'] = true;
60
61 if ( 'scripts' === $assets_type ) {
62 wp_enqueue_script( $asset_name );
63 } else {
64 wp_enqueue_style( $asset_name );
65 }
66 }
67 }
68 }
69
70 /**
71 * @param array $assets {
72 * @type array 'styles'
73 * @type array 'scripts'
74 * }
75 */
76 public function add_assets( array $assets ) {
77 if ( ! $this->assets ) {
78 $this->init_assets();
79 }
80
81 $this->assets = array_replace_recursive( $this->assets, $assets );
82 }
83
84 /**
85 * @deprecated 3.22.0
86 */
87 public function enqueue_assets() {
88 $assets = $this->get_assets();
89 $is_preview_mode = Plugin::$instance->preview->is_preview_mode();
90
91 foreach ( $assets as $assets_type => $assets_type_data ) {
92 foreach ( $assets_type_data as $asset_name => $asset_data ) {
93 if ( ! empty( $asset_data['enabled'] ) || $is_preview_mode ) {
94 if ( 'scripts' === $assets_type ) {
95 wp_enqueue_script( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'], true );
96 } else {
97 wp_enqueue_style( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'] );
98 }
99 }
100 }
101 }
102 }
103
104 private function register_assets() {
105 $assets = $this->get_assets();
106
107 foreach ( $assets as $assets_type => $assets_type_data ) {
108 foreach ( $assets_type_data as $asset_name => $asset_data ) {
109 if ( 'scripts' === $assets_type ) {
110 wp_register_script( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'], true );
111 } else {
112 wp_register_style( $asset_name, $asset_data['src'], $asset_data['dependencies'], $asset_data['version'] );
113 }
114 }
115 }
116 }
117
118 public function __construct() {
119 parent::__construct();
120
121 $this->register_assets();
122 }
123 }
124