PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.0-dev1
Elementor Website Builder – more than just a page builder v3.6.0-dev1
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 / trunk / core / common / app.php

app.php in Elementor Website Builder – more than just a page builder 3.6.0-dev1, at trunk/core/common/app.php

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