PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev2
Elementor Website Builder – more than just a page builder v3.32.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 / app / app.php

app.php in Elementor Website Builder – more than just a page builder 3.32.0-dev2, at app/app.php

328 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App;
3
4 use Elementor\App\AdminMenuItems\Theme_Builder_Menu_Item;
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Core\Experiments\Manager as ExperimentsManager;
7 use Elementor\Modules\WebCli\Module as WebCLIModule;
8 use Elementor\Core\Base\App as BaseApp;
9 use Elementor\Core\Settings\Manager as SettingsManager;
10 use Elementor\Plugin;
11 use Elementor\TemplateLibrary\Source_Local;
12 use Elementor\User;
13 use Elementor\Utils;
14 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
15 use Elementor\Core\Utils\Assets_Config_Provider;
16 use Elementor\Core\Utils\Collection;
17
18 use Elementor\App\Modules\ImportExport\Module as ImportExportModule;
19 use Elementor\App\Modules\KitLibrary\Module as KitLibraryModule;
20 use Elementor\App\Modules\ImportExportCustomization\Module as ImportExportCustomizationModule;
21 use Elementor\App\Modules\SiteEditor\Module as SiteEditorModule;
22 use Elementor\App\Modules\Onboarding\Module as OnboardingModule;
23
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit; // Exit if accessed directly.
26 }
27
28 class App extends BaseApp {
29
30 const PAGE_ID = 'elementor-app';
31
32 /**
33 * Get module name.
34 *
35 * Retrieve the module name.
36 *
37 * @since 3.0.0
38 * @access public
39 *
40 * @return string Module name.
41 */
42 public function get_name() {
43 return 'app';
44 }
45
46 public function get_base_url() {
47 return admin_url( 'admin.php?page=' . self::PAGE_ID . '&ver=' . ELEMENTOR_VERSION );
48 }
49
50 private function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
51 $admin_menu->register( static::PAGE_ID, new Theme_Builder_Menu_Item() );
52 }
53
54 public function fix_submenu( $menu ) {
55 global $submenu;
56
57 if ( is_multisite() && is_network_admin() ) {
58 return $menu;
59 }
60
61 // Non admin role / custom wp menu.
62 if ( empty( $submenu[ Source_Local::ADMIN_MENU_SLUG ] ) ) {
63 return $menu;
64 }
65
66 // Hack to add a link to sub menu.
67 foreach ( $submenu[ Source_Local::ADMIN_MENU_SLUG ] as &$item ) {
68 if ( self::PAGE_ID === $item[2] ) {
69 $item[2] = $this->get_settings( 'menu_url' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
70 $item[4] = 'elementor-app-link'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
71 }
72 }
73
74 return $menu;
75 }
76
77 public function is_current() {
78 return ( ! empty( $_GET['page'] ) && self::PAGE_ID === $_GET['page'] );
79 }
80
81 public function admin_init() {
82 do_action( 'elementor/app/init', $this );
83
84 // Add the introduction and user settings only when it is needed (when loading the app and not in the editor or admin pages)
85 $this->set_settings( 'user', [
86 'introduction' => (object) User::get_introduction_meta(),
87 'is_administrator' => current_user_can( 'manage_options' ),
88 'restrictions' => Plugin::$instance->role_manager->get_user_restrictions_array(),
89 ] );
90
91 $this->enqueue_assets();
92
93 remove_action( 'wp_print_styles', 'print_emoji_styles' );
94
95 // Setup default heartbeat options
96 // TODO: Enable heartbeat.
97 add_filter( 'heartbeat_settings', function( $settings ) {
98 $settings['interval'] = 15;
99 return $settings;
100 } );
101
102 $this->render();
103 die;
104 }
105
106 protected function get_init_settings() {
107 $referer = wp_get_referer();
108
109 return [
110 'menu_url' => $this->get_base_url() . '#site-editor/promotion',
111 'assets_url' => ELEMENTOR_ASSETS_URL,
112 'pages_url' => admin_url( 'edit.php?post_type=page' ),
113 'return_url' => $referer ? $referer : admin_url(),
114 'hasPro' => Utils::has_pro(),
115 'admin_url' => admin_url(),
116 'login_url' => wp_login_url(),
117 'base_url' => $this->get_base_url(),
118 'home_url' => home_url(),
119 'promotion' => Filtered_Promotions_Manager::get_filtered_promotion_data(
120 [ 'upgrade_url' => 'https://go.elementor.com/go-pro-theme-builder/' ],
121 'elementor/site-editor/promotion',
122 'upgrade_url'
123 ),
124 ];
125 }
126
127 private function render() {
128 require __DIR__ . '/view.php';
129 }
130
131 /**
132 * Get Elementor editor theme color preference.
133 *
134 * Retrieve the user theme color preference as defined by editor preferences manager.
135 *
136 * @since 3.0.0
137 * @access private
138 *
139 * @return string Preferred editor theme.
140 */
141 private function get_elementor_ui_theme_preference() {
142 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
143
144 return $editor_preferences->get_model()->get_settings( 'ui_theme' );
145 }
146
147 /**
148 * Enqueue dark theme detection script.
149 *
150 * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
151 *
152 * @since 3.0.0
153 * @access private
154 */
155 private function enqueue_dark_theme_detection_script() {
156 if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
157 wp_add_inline_script( 'elementor-app',
158 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
159 { document.body.classList.add( `eps-theme-dark` ); }' );
160 }
161 }
162
163 private function register_packages() {
164 $assets_config_provider = ( new Assets_Config_Provider() )
165 ->set_path_resolver( function ( $name ) {
166 return ELEMENTOR_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php";
167 } );
168
169 Collection::make( [ 'ui', 'icons' ] )
170 ->each( function( $package ) use ( $assets_config_provider ) {
171 $suffix = Utils::is_script_debug() ? '' : '.min';
172 $config = $assets_config_provider->load( $package )->get( $package );
173
174 if ( ! $config ) {
175 return;
176 }
177
178 wp_register_script(
179 $config['handle'],
180 ELEMENTOR_ASSETS_URL . "js/packages/{$package}/{$package}{$suffix}.js",
181 $config['deps'],
182 ELEMENTOR_VERSION,
183 true
184 );
185 } );
186 }
187
188 private function enqueue_assets() {
189 Plugin::$instance->init_common();
190
191 $this->register_packages();
192
193 /** @var WebCLIModule $web_cli */
194 $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
195 $web_cli->register_scripts();
196
197 Plugin::$instance->common->register_scripts();
198
199 wp_register_style(
200 'select2',
201 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
202 [],
203 '4.0.6-rc.1'
204 );
205
206 Plugin::$instance->common->register_styles();
207
208 wp_register_style(
209 'select2',
210 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
211 [],
212 '4.0.6-rc.1'
213 );
214
215 wp_enqueue_style(
216 'elementor-app',
217 $this->get_css_assets_url( 'app', null, 'default', true ),
218 [
219 'select2',
220 'elementor-icons',
221 'elementor-common',
222 'select2',
223 ],
224 ELEMENTOR_VERSION
225 );
226
227 wp_enqueue_script(
228 'elementor-app-packages',
229 $this->get_js_assets_url( 'app-packages' ),
230 [
231 'wp-i18n',
232 'react',
233 ],
234 ELEMENTOR_VERSION,
235 true
236 );
237
238 wp_register_script(
239 'select2',
240 $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
241 [
242 'jquery',
243 ],
244 '4.0.6-rc.1',
245 true
246 );
247
248 wp_enqueue_script(
249 'elementor-app',
250 $this->get_js_assets_url( 'app' ),
251 [
252 'wp-url',
253 'wp-i18n',
254 'elementor-v2-ui',
255 'elementor-v2-icons',
256 'react',
257 'react-dom',
258 'select2',
259 ],
260 ELEMENTOR_VERSION,
261 true
262 );
263
264 $this->enqueue_dark_theme_detection_script();
265
266 wp_set_script_translations( 'elementor-app-packages', 'elementor' );
267 wp_set_script_translations( 'elementor-app', 'elementor' );
268
269 $this->print_config();
270 }
271
272 public function enqueue_app_loader() {
273 wp_enqueue_script(
274 'elementor-app-loader',
275 $this->get_js_assets_url( 'app-loader' ),
276 [
277 'elementor-common',
278 ],
279 ELEMENTOR_VERSION,
280 true
281 );
282
283 $this->print_config( 'elementor-app-loader' );
284 }
285
286 private function register_import_export_customization_experiment() {
287 Plugin::$instance->experiments->add_feature( [
288 'name' => 'import-export-customization',
289 'title' => esc_html__( 'Import/Export Customization', 'elementor' ),
290 'description' => esc_html__( 'Enhanced import/export for website templates. Selectively include site content, templates, and settings with advanced granular control.', 'elementor' ),
291 'release_status' => ExperimentsManager::RELEASE_STATUS_BETA,
292 'default' => ExperimentsManager::STATE_ACTIVE,
293 ] );
294 }
295
296 public function __construct() {
297 $this->register_import_export_customization_experiment();
298
299 $this->add_component( 'site-editor', new SiteEditorModule() );
300
301 if ( current_user_can( 'manage_options' ) || Utils::is_wp_cli() ) {
302 $this->add_component( 'import-export', new ImportExportModule() );
303
304 if ( Plugin::$instance->experiments->is_feature_active( 'import-export-customization' ) ) {
305 $this->add_component( 'import-export-customization', new ImportExportCustomizationModule() );
306 }
307
308 // Kit library is depended on import-export
309 $this->add_component( 'kit-library', new KitLibraryModule() );
310 }
311
312 $this->add_component( 'onboarding', new OnboardingModule() );
313
314 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
315 $this->register_admin_menu( $admin_menu );
316 }, Source_Local::ADMIN_MENU_PRIORITY + 10 );
317
318 // Happens after WP plugin page validation.
319 add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
320
321 if ( $this->is_current() ) {
322 add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
323 } else {
324 add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
325 }
326 }
327 }
328