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

app.php in Elementor Website Builder – more than just a page builder 3.7.0, at core/app/app.php

273 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\App;
3
4 use Elementor\Icons_Manager;
5 use Elementor\Modules\WebCli\Module as WebCLIModule;
6 use Elementor\Core\Base\App as BaseApp;
7 use Elementor\Core\Settings\Manager as SettingsManager;
8 use Elementor\Plugin;
9 use Elementor\TemplateLibrary\Source_Local;
10 use Elementor\Utils;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 class App extends BaseApp {
17
18 const PAGE_ID = 'elementor-app';
19
20 /**
21 * Get module name.
22 *
23 * Retrieve the module name.
24 *
25 * @since 3.0.0
26 * @access public
27 *
28 * @return string Module name.
29 */
30 public function get_name() {
31 return 'app';
32 }
33
34 public function get_base_url() {
35 return admin_url( 'admin.php?page=' . self::PAGE_ID . '&ver=' . ELEMENTOR_VERSION );
36 }
37
38 public function register_admin_menu() {
39 add_submenu_page(
40 Source_Local::ADMIN_MENU_SLUG,
41 esc_html__( 'Theme Builder', 'elementor' ),
42 esc_html__( 'Theme Builder', 'elementor' ),
43 'manage_options',
44 self::PAGE_ID
45 );
46 }
47
48 public function fix_submenu( $menu ) {
49 global $submenu;
50
51 if ( is_multisite() && is_network_admin() ) {
52 return $menu;
53 }
54
55 // Non admin role / custom wp menu.
56 if ( empty( $submenu[ Source_Local::ADMIN_MENU_SLUG ] ) ) {
57 return $menu;
58 }
59
60 // Hack to add a link to sub menu.
61 foreach ( $submenu[ Source_Local::ADMIN_MENU_SLUG ] as &$item ) {
62 if ( self::PAGE_ID === $item[2] ) {
63 $item[2] = $this->get_settings( 'menu_url' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
64 $item[4] = 'elementor-app-link'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
65 }
66 }
67
68 return $menu;
69 }
70
71 public function is_current() {
72 return ( ! empty( $_GET['page'] ) && self::PAGE_ID === $_GET['page'] );
73 }
74
75 public function admin_init() {
76 do_action( 'elementor/app/init', $this );
77
78 $this->enqueue_assets();
79
80 // Setup default heartbeat options
81 // TODO: Enable heartbeat.
82 add_filter( 'heartbeat_settings', function( $settings ) {
83 $settings['interval'] = 15;
84 return $settings;
85 } );
86
87 $this->render();
88 die;
89 }
90
91 protected function get_init_settings() {
92 $referer = wp_get_referer();
93
94 return [
95 'menu_url' => $this->get_base_url() . '#site-editor/promotion',
96 'assets_url' => ELEMENTOR_ASSETS_URL,
97 'return_url' => $referer ? $referer : admin_url(),
98 'hasPro' => Utils::has_pro(),
99 'admin_url' => admin_url(),
100 'login_url' => wp_login_url(),
101 'base_url' => $this->get_base_url(),
102 ];
103 }
104
105 private function render() {
106 require __DIR__ . '/view.php';
107 }
108
109 /**
110 * Get Elementor UI theme preference.
111 *
112 * Retrieve the user UI theme preference as defined by editor preferences manager.
113 *
114 * @since 3.0.0
115 * @access private
116 *
117 * @return string Preferred UI theme.
118 */
119 private function get_elementor_ui_theme_preference() {
120 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
121
122 return $editor_preferences->get_model()->get_settings( 'ui_theme' );
123 }
124
125 /**
126 * Enqueue dark theme detection script.
127 *
128 * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
129 *
130 * @since 3.0.0
131 * @access private
132 */
133 private function enqueue_dark_theme_detection_script() {
134 if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
135 wp_add_inline_script( 'elementor-app',
136 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
137 { document.body.classList.add( `eps-theme-dark` ); }' );
138 }
139 }
140
141 private function enqueue_assets() {
142 Plugin::$instance->init_common();
143
144 /** @var WebCLIModule $web_cli */
145 $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
146 $web_cli->register_scripts();
147
148 Plugin::$instance->common->register_scripts();
149
150 wp_register_style(
151 'select2',
152 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
153 [],
154 '4.0.6-rc.1'
155 );
156
157 wp_register_style(
158 'elementor-icons',
159 $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
160 [],
161 Icons_Manager::ELEMENTOR_ICONS_VERSION
162 );
163
164 wp_register_style(
165 'elementor-common',
166 $this->get_css_assets_url( 'common', null, 'default', true ),
167 [],
168 ELEMENTOR_VERSION
169 );
170
171 wp_register_style(
172 'select2',
173 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
174 [],
175 '4.0.6-rc.1'
176 );
177
178 wp_enqueue_style(
179 'elementor-app',
180 $this->get_css_assets_url( 'app', null, 'default', true ),
181 [
182 'select2',
183 'elementor-icons',
184 'elementor-common',
185 'select2',
186 ],
187 ELEMENTOR_VERSION
188 );
189
190 wp_enqueue_script(
191 'elementor-app-packages',
192 $this->get_js_assets_url( 'app-packages' ),
193 [
194 'wp-i18n',
195 'react',
196 ],
197 ELEMENTOR_VERSION,
198 true
199 );
200
201 wp_register_script(
202 'select2',
203 $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
204 [
205 'jquery',
206 ],
207 '4.0.6-rc.1',
208 true
209 );
210
211 wp_enqueue_script(
212 'elementor-app',
213 $this->get_js_assets_url( 'app' ),
214 [
215 'wp-url',
216 'wp-i18n',
217 'react',
218 'react-dom',
219 'select2',
220 ],
221 ELEMENTOR_VERSION,
222 true
223 );
224
225 if ( ! $this->get_settings( 'disable_dark_theme' ) ) {
226 $this->enqueue_dark_theme_detection_script();
227 }
228
229 wp_set_script_translations( 'elementor-app-packages', 'elementor' );
230 wp_set_script_translations( 'elementor-app', 'elementor' );
231
232 $this->print_config();
233 }
234
235 public function enqueue_app_loader() {
236 wp_enqueue_script(
237 'elementor-app-loader',
238 $this->get_js_assets_url( 'app-loader' ),
239 [
240 'elementor-common',
241 ],
242 ELEMENTOR_VERSION,
243 true
244 );
245
246 $this->print_config( 'elementor-app-loader' );
247 }
248
249 public function __construct() {
250 $this->add_component( 'site-editor', new Modules\SiteEditor\Module() );
251
252 if ( current_user_can( 'manage_options' ) && Plugin::$instance->experiments->is_feature_active( 'e_import_export' ) || Utils::is_wp_cli() ) {
253 $this->add_component( 'import-export', new Modules\ImportExport\Module() );
254
255 // Kit library is depended on import-export
256 $this->add_component( 'kit-library', new Modules\KitLibrary\Module() );
257 }
258
259 $this->add_component( 'onboarding', new Modules\Onboarding\Module() );
260
261 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 21 /* after Elementor page */ );
262
263 // Happens after WP plugin page validation.
264 add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
265
266 if ( $this->is_current() ) {
267 add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
268 } else {
269 add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
270 }
271 }
272 }
273