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

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

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