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

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