PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.3
Elementor Website Builder – more than just a page builder v3.6.3
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 3.6.3, at core/common/app.php

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