PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.4
Elementor Website Builder – more than just a page builder v4.2.4
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 / common / app.php

app.php in Elementor Website Builder – more than just a page builder 4.2.4, at core/common/app.php

320 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Common;
3
4 use Elementor\Core\Base\App as BaseApp;
5 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
6 use Elementor\Core\Common\Modules\Finder\Module as Finder;
7 use Elementor\Core\Common\Modules\Connect\Module as Connect;
8 use Elementor\Core\Common\Modules\EventTracker\Module as Event_Tracker;
9 use Elementor\Core\Common\Modules\EventsManager\Module as Events_Manager;
10 use Elementor\Core\Files\Uploads_Manager;
11 use Elementor\Icons_Manager;
12 use Elementor\Plugin;
13 use Elementor\Utils;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * App
21 *
22 * Elementor's common app that groups shared functionality, components and configuration
23 *
24 * @since 2.3.0
25 */
26 class App extends BaseApp {
27
28 private $templates = [];
29
30 /**
31 * App constructor.
32 *
33 * @since 2.3.0
34 * @access public
35 */
36 public function __construct() {
37 $this->add_default_templates();
38
39 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'register_scripts' ], 9 );
40 add_action( 'admin_enqueue_scripts', [ $this, 'register_scripts' ], 9 );
41 add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ], 9 );
42
43 add_action( 'elementor/editor/before_enqueue_styles', [ $this, 'register_styles' ] );
44 add_action( 'admin_enqueue_scripts', [ $this, 'register_styles' ] );
45 add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ], 9 );
46
47 add_action( 'elementor/editor/footer', [ $this, 'print_templates' ] );
48 add_action( 'admin_footer', [ $this, 'print_templates' ] );
49 add_action( 'wp_footer', [ $this, 'print_templates' ] );
50 }
51
52 /**
53 * Init components
54 *
55 * Initializing common components.
56 *
57 * @since 2.3.0
58 * @access public
59 */
60 public function init_components() {
61 $this->add_component( 'ajax', new Ajax() );
62
63 if ( current_user_can( 'manage_options' ) ) {
64 if ( ! is_customize_preview() ) {
65 $this->add_component( 'finder', new Finder() );
66 }
67 }
68
69 $this->add_component( 'connect', new Connect() );
70
71 $this->add_component( 'event-tracker', new Event_Tracker() );
72
73 Plugin::$instance->experiments->add_feature( Events_Manager::get_experimental_data() );
74
75 if ( Plugin::$instance->experiments->is_feature_active( Events_Manager::EXPERIMENT_NAME ) ) {
76 $this->add_component( 'events-manager', new Events_Manager() );
77 }
78 }
79
80 /**
81 * Get name.
82 *
83 * Retrieve the app name.
84 *
85 * @since 2.3.0
86 * @access public
87 *
88 * @return string Common app name.
89 */
90 public function get_name() {
91 return 'common';
92 }
93
94 /**
95 * Register scripts.
96 *
97 * Register common scripts.
98 *
99 * @since 2.3.0
100 * @access public
101 */
102 public function register_scripts() {
103 wp_register_script(
104 'elementor-vendors-redux',
105 $this->get_js_assets_url( 'vendors-redux' ),
106 [
107 'react',
108 'react-dom',
109 ],
110 ELEMENTOR_VERSION,
111 true
112 );
113
114 wp_register_script(
115 'elementor-common-modules',
116 $this->get_js_assets_url( 'common-modules' ),
117 [
118 'elementor-vendors-redux',
119 ],
120 ELEMENTOR_VERSION,
121 true
122 );
123
124 wp_register_script(
125 'backbone-marionette',
126 $this->get_js_assets_url( 'backbone.marionette', 'assets/lib/backbone/' ),
127 [
128 'backbone',
129 ],
130 '2.4.5.e1',
131 true
132 );
133
134 wp_register_script(
135 'backbone-radio',
136 $this->get_js_assets_url( 'backbone.radio', 'assets/lib/backbone/' ),
137 [
138 'backbone',
139 ],
140 '1.0.4',
141 true
142 );
143
144 wp_register_script(
145 'elementor-dialog',
146 $this->get_js_assets_url( 'dialog', 'assets/lib/dialog/' ),
147 [
148 'jquery-ui-position',
149 ],
150 '4.9.0',
151 true
152 );
153
154 wp_enqueue_script(
155 'elementor-common',
156 $this->get_js_assets_url( 'common' ),
157 [
158 'jquery',
159 'jquery-ui-draggable',
160 'backbone-marionette',
161 'backbone-radio',
162 'elementor-common-modules',
163 'elementor-web-cli',
164 'elementor-dialog',
165 'wp-api-request',
166 'elementor-dev-tools',
167 ],
168 ELEMENTOR_VERSION,
169 true
170 );
171
172 wp_set_script_translations( 'elementor-common', 'elementor' );
173
174 $this->print_config();
175
176 // Used for external plugins.
177 do_action( 'elementor/common/after_register_scripts', $this );
178 }
179
180 /**
181 * Register styles.
182 *
183 * Register common styles.
184 *
185 * @since 2.3.0
186 * @access public
187 */
188 public function register_styles() {
189 wp_register_style(
190 'elementor-icons',
191 $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
192 [],
193 Icons_Manager::ELEMENTOR_ICONS_VERSION
194 );
195
196 wp_enqueue_style(
197 'elementor-common',
198 $this->get_css_assets_url( 'common', null, 'default', true ),
199 [
200 'elementor-icons',
201 ],
202 ELEMENTOR_VERSION
203 );
204
205 wp_enqueue_style(
206 'e-theme-ui-light',
207 $this->get_css_assets_url( 'theme-light' ),
208 [],
209 ELEMENTOR_VERSION
210 );
211 }
212
213 /**
214 * Add template.
215 *
216 * @since 2.3.0
217 * @access public
218 *
219 * @param string $template Can be either a link to template file or template
220 * HTML content.
221 * @param string $type Optional. Whether to handle the template as path
222 * or text. Default is `path`.
223 */
224 public function add_template( $template, $type = 'path' ) {
225 if ( 'path' === $type ) {
226 ob_start();
227
228 include $template;
229
230 $template = ob_get_clean();
231 }
232
233 $this->templates[] = $template;
234 }
235
236 /**
237 * Print Templates
238 *
239 * Prints all registered templates.
240 *
241 * @since 2.3.0
242 * @access public
243 */
244 public function print_templates() {
245 foreach ( $this->templates as $template ) {
246 echo $template; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
247 }
248 }
249
250 /**
251 * Get init settings.
252 *
253 * Define the default/initial settings of the common app.
254 *
255 * @since 2.3.0
256 * @access protected
257 *
258 * @return array
259 */
260 protected function get_init_settings() {
261 $active_experimental_features = Plugin::$instance->experiments->get_active_features();
262 $all_experimental_features = Plugin::$instance->experiments->get_features();
263
264 $active_experimental_features = array_fill_keys( array_keys( $active_experimental_features ), true );
265 $all_experimental_features = array_map(
266 function( $feature ) {
267 return Plugin::$instance->experiments->is_feature_active( $feature['name'] );
268 },
269 $all_experimental_features
270 );
271
272 $config = [
273 'version' => ELEMENTOR_VERSION,
274 'isRTL' => is_rtl(),
275 'isDebug' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
276 'isElementorDebug' => Utils::is_elementor_debug(),
277 'activeModules' => array_keys( $this->get_components() ),
278 'experimentalFeatures' => $active_experimental_features,
279 'allExperimentalFeatures' => $all_experimental_features,
280 'urls' => [
281 'assets' => ELEMENTOR_ASSETS_URL,
282 'rest' => get_rest_url(),
283 ],
284 'filesUpload' => [
285 'unfilteredFiles' => Uploads_Manager::are_unfiltered_uploads_enabled(),
286 ],
287 'editor_events' => Events_Manager::get_editor_events_config(),
288 ];
289
290 /**
291 * Localize common settings.
292 *
293 * Filters the editor localized settings.
294 *
295 * @since 1.0.0
296 *
297 * @param array $config Common configuration.
298 */
299 return apply_filters( 'elementor/common/localize_settings', $config );
300 }
301
302 /**
303 * Add default templates.
304 *
305 * Register common app default templates.
306 *
307 * @since 2.3.0
308 * @access private
309 */
310 private function add_default_templates() {
311 $default_templates = [
312 'includes/editor-templates/library-layout.php',
313 ];
314
315 foreach ( $default_templates as $template ) {
316 $this->add_template( ELEMENTOR_PATH . $template );
317 }
318 }
319 }
320