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

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

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