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

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