PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.0-beta1
Elementor Website Builder – more than just a page builder v3.34.0-beta1
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.34.0-beta1, at app/app.php

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