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

328 lines 8.9 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 'promotion' => Filtered_Promotions_Manager::get_filtered_promotion_data(
119 [ 'upgrade_url' => 'https://go.elementor.com/go-pro-theme-builder/' ],
120 'elementor/site-editor/promotion',
121 'upgrade_url'
122 ),
123 ];
124 }
125
126 private function render() {
127 require __DIR__ . '/view.php';
128 }
129
130 /**
131 * Get Elementor editor theme color preference.
132 *
133 * Retrieve the user theme color preference as defined by editor preferences manager.
134 *
135 * @since 3.0.0
136 * @access private
137 *
138 * @return string Preferred editor theme.
139 */
140 private function get_elementor_ui_theme_preference() {
141 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
142
143 return $editor_preferences->get_model()->get_settings( 'ui_theme' );
144 }
145
146 /**
147 * Enqueue dark theme detection script.
148 *
149 * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
150 *
151 * @since 3.0.0
152 * @access private
153 */
154 private function enqueue_dark_theme_detection_script() {
155 if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
156 wp_add_inline_script( 'elementor-app',
157 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
158 { document.body.classList.add( `eps-theme-dark` ); }' );
159 }
160 }
161
162 private function register_packages() {
163 $assets_config_provider = ( new Assets_Config_Provider() )
164 ->set_path_resolver( function ( $name ) {
165 return ELEMENTOR_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php";
166 } );
167
168 Collection::make( [ 'ui', 'icons' ] )
169 ->each( function( $package ) use ( $assets_config_provider ) {
170 $suffix = Utils::is_script_debug() ? '' : '.min';
171 $config = $assets_config_provider->load( $package )->get( $package );
172
173 if ( ! $config ) {
174 return;
175 }
176
177 wp_register_script(
178 $config['handle'],
179 ELEMENTOR_ASSETS_URL . "js/packages/{$package}/{$package}{$suffix}.js",
180 $config['deps'],
181 ELEMENTOR_VERSION,
182 true
183 );
184 } );
185 }
186
187 private function enqueue_assets() {
188 Plugin::$instance->init_common();
189
190 $this->register_packages();
191
192 /** @var WebCLIModule $web_cli */
193 $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
194 $web_cli->register_scripts();
195
196 Plugin::$instance->common->register_scripts();
197
198 wp_register_style(
199 'select2',
200 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
201 [],
202 '4.0.6-rc.1'
203 );
204
205 Plugin::$instance->common->register_styles();
206
207 wp_register_style(
208 'select2',
209 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
210 [],
211 '4.0.6-rc.1'
212 );
213
214 wp_enqueue_style(
215 'elementor-app',
216 $this->get_css_assets_url( 'app', null, 'default', true ),
217 [
218 'select2',
219 'elementor-icons',
220 'elementor-common',
221 'select2',
222 ],
223 ELEMENTOR_VERSION
224 );
225
226 wp_enqueue_script(
227 'elementor-app-packages',
228 $this->get_js_assets_url( 'app-packages' ),
229 [
230 'wp-i18n',
231 'react',
232 ],
233 ELEMENTOR_VERSION,
234 true
235 );
236
237 wp_register_script(
238 'select2',
239 $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
240 [
241 'jquery',
242 ],
243 '4.0.6-rc.1',
244 true
245 );
246
247 wp_enqueue_script(
248 'elementor-app',
249 $this->get_js_assets_url( 'app' ),
250 [
251 'wp-url',
252 'wp-i18n',
253 'elementor-v2-ui',
254 'elementor-v2-icons',
255 'react',
256 'react-dom',
257 'select2',
258 ],
259 ELEMENTOR_VERSION,
260 true
261 );
262
263 $this->enqueue_dark_theme_detection_script();
264
265 wp_set_script_translations( 'elementor-app-packages', 'elementor' );
266 wp_set_script_translations( 'elementor-app', 'elementor' );
267
268 $this->print_config();
269 }
270
271 public function enqueue_app_loader() {
272 wp_enqueue_script(
273 'elementor-app-loader',
274 $this->get_js_assets_url( 'app-loader' ),
275 [
276 'elementor-common',
277 ],
278 ELEMENTOR_VERSION,
279 true
280 );
281
282 $this->print_config( 'elementor-app-loader' );
283 }
284
285 private function register_import_export_customization_experiment() {
286 Plugin::$instance->experiments->add_feature( [
287 'name' => 'import-export-customization',
288 'title' => esc_html__( 'Import/Export Customization', 'elementor' ),
289 'description' => esc_html__( 'Enable advanced customization options for import/export functionality.', 'elementor' ),
290 'hidden' => true,
291 'release_status' => ExperimentsManager::RELEASE_STATUS_ALPHA,
292 'default' => ExperimentsManager::STATE_INACTIVE,
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