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

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

261 lines 6.0 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 ];
100 }
101
102 private function render() {
103 require __DIR__ . '/view.php';
104 }
105
106 /**
107 * Get Elementor UI theme preference.
108 *
109 * Retrieve the user UI theme preference as defined by editor preferences manager.
110 *
111 * @since 3.0.0
112 * @access private
113 *
114 * @return string Preferred UI theme.
115 */
116 private function get_elementor_ui_theme_preference() {
117 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
118
119 return $editor_preferences->get_model()->get_settings( 'ui_theme' );
120 }
121
122 /**
123 * Enqueue dark theme detection script.
124 *
125 * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
126 *
127 * @since 3.0.0
128 * @access private
129 */
130 private function enqueue_dark_theme_detection_script() {
131 if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
132 wp_add_inline_script( 'elementor-app',
133 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
134 { document.body.classList.add( `eps-theme-dark` ); }' );
135 }
136 }
137
138 private function enqueue_assets() {
139 Plugin::$instance->init_common();
140 Plugin::$instance->common->register_scripts();
141
142 wp_register_style(
143 'select2',
144 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
145 [],
146 '4.0.6-rc.1'
147 );
148
149 wp_register_style(
150 'elementor-icons',
151 $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
152 [],
153 '5.14.0'
154 );
155
156 wp_register_style(
157 'elementor-common',
158 $this->get_css_assets_url( 'common', null, 'default', true ),
159 [],
160 ELEMENTOR_VERSION
161 );
162
163 wp_register_style(
164 'select2',
165 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
166 [],
167 '4.0.6-rc.1'
168 );
169
170 wp_enqueue_style(
171 'elementor-app',
172 $this->get_css_assets_url( 'app', null, 'default', true ),
173 [
174 'select2',
175 'elementor-icons',
176 'elementor-common',
177 'select2',
178 ],
179 ELEMENTOR_VERSION
180 );
181
182 wp_enqueue_script(
183 'elementor-app-packages',
184 $this->get_js_assets_url( 'app-packages' ),
185 [
186 'wp-i18n',
187 'react',
188 ],
189 ELEMENTOR_VERSION,
190 true
191 );
192
193 wp_register_script(
194 'select2',
195 $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
196 [
197 'jquery',
198 ],
199 '4.0.6-rc.1',
200 true
201 );
202
203 wp_enqueue_script(
204 'elementor-app',
205 $this->get_js_assets_url( 'app' ),
206 [
207 'wp-url',
208 'wp-i18n',
209 'react',
210 'react-dom',
211 'select2',
212 ],
213 ELEMENTOR_VERSION,
214 true
215 );
216
217 $this->enqueue_dark_theme_detection_script();
218
219 wp_set_script_translations( 'elementor-app-packages', 'elementor' );
220 wp_set_script_translations( 'elementor-app', 'elementor' );
221
222 $this->print_config();
223 }
224
225 public function enqueue_app_loader() {
226 wp_enqueue_script(
227 'elementor-app-loader',
228 $this->get_js_assets_url( 'app-loader' ),
229 [
230 'elementor-common',
231 ],
232 ELEMENTOR_VERSION,
233 true
234 );
235
236 $this->print_config( 'elementor-app-loader' );
237 }
238
239 public function __construct() {
240 $this->add_component( 'site-editor', new Modules\SiteEditor\Module() );
241
242 if ( current_user_can( 'manage_options' ) && Plugin::$instance->experiments->is_feature_active( 'e_import_export' ) || Utils::is_wp_cli() ) {
243 $this->add_component( 'import-export', new Modules\ImportExport\Module() );
244
245 // Kit library is depended on import-export
246 $this->add_component( 'kit-library', new Modules\KitLibrary\Module() );
247 }
248
249 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 21 /* after Elementor page */ );
250
251 // Happens after WP plugin page validation.
252 add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
253
254 if ( $this->is_current() ) {
255 add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
256 } else {
257 add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
258 }
259 }
260 }
261