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

265 lines 6.6 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\Modules\WebCli\Module as WebCLIModule;
7 use Elementor\Core\Base\App as BaseApp;
8 use Elementor\Core\Settings\Manager as SettingsManager;
9 use Elementor\Plugin;
10 use Elementor\TemplateLibrary\Source_Local;
11 use Elementor\User;
12 use Elementor\Utils;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 class App extends BaseApp {
19
20 const PAGE_ID = 'elementor-app';
21
22 /**
23 * Get module name.
24 *
25 * Retrieve the module name.
26 *
27 * @since 3.0.0
28 * @access public
29 *
30 * @return string Module name.
31 */
32 public function get_name() {
33 return 'app';
34 }
35
36 public function get_base_url() {
37 return admin_url( 'admin.php?page=' . self::PAGE_ID . '&ver=' . ELEMENTOR_VERSION );
38 }
39
40 private function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
41 $admin_menu->register( static::PAGE_ID, new Theme_Builder_Menu_Item() );
42 }
43
44 public function fix_submenu( $menu ) {
45 global $submenu;
46
47 if ( is_multisite() && is_network_admin() ) {
48 return $menu;
49 }
50
51 // Non admin role / custom wp menu.
52 if ( empty( $submenu[ Source_Local::ADMIN_MENU_SLUG ] ) ) {
53 return $menu;
54 }
55
56 // Hack to add a link to sub menu.
57 foreach ( $submenu[ Source_Local::ADMIN_MENU_SLUG ] as &$item ) {
58 if ( self::PAGE_ID === $item[2] ) {
59 $item[2] = $this->get_settings( 'menu_url' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
60 $item[4] = 'elementor-app-link'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
61 }
62 }
63
64 return $menu;
65 }
66
67 public function is_current() {
68 return ( ! empty( $_GET['page'] ) && self::PAGE_ID === $_GET['page'] );
69 }
70
71 public function admin_init() {
72 do_action( 'elementor/app/init', $this );
73
74 // Add the introduction and user settings only when it is needed (when loading the app and not in the editor or admin pages)
75 $this->set_settings( 'user', [
76 'introduction' => (object) User::get_introduction_meta(),
77 'is_administrator' => current_user_can( 'manage_options' ),
78 'restrictions' => Plugin::$instance->role_manager->get_user_restrictions_array(),
79 ] );
80
81 $this->enqueue_assets();
82
83 // Setup default heartbeat options
84 // TODO: Enable heartbeat.
85 add_filter( 'heartbeat_settings', function( $settings ) {
86 $settings['interval'] = 15;
87 return $settings;
88 } );
89
90 $this->render();
91 die;
92 }
93
94 protected function get_init_settings() {
95 $referer = wp_get_referer();
96
97 return [
98 'menu_url' => $this->get_base_url() . '#site-editor/promotion',
99 'assets_url' => ELEMENTOR_ASSETS_URL,
100 'pages_url' => admin_url( 'edit.php?post_type=page' ),
101 'return_url' => $referer ? $referer : admin_url(),
102 'hasPro' => Utils::has_pro(),
103 'admin_url' => admin_url(),
104 'login_url' => wp_login_url(),
105 'base_url' => $this->get_base_url(),
106 ];
107 }
108
109 private function render() {
110 require __DIR__ . '/view.php';
111 }
112
113 /**
114 * Get Elementor UI theme preference.
115 *
116 * Retrieve the user UI theme preference as defined by editor preferences manager.
117 *
118 * @since 3.0.0
119 * @access private
120 *
121 * @return string Preferred UI theme.
122 */
123 private function get_elementor_ui_theme_preference() {
124 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
125
126 return $editor_preferences->get_model()->get_settings( 'ui_theme' );
127 }
128
129 /**
130 * Enqueue dark theme detection script.
131 *
132 * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
133 *
134 * @since 3.0.0
135 * @access private
136 */
137 private function enqueue_dark_theme_detection_script() {
138 if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
139 wp_add_inline_script( 'elementor-app',
140 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
141 { document.body.classList.add( `eps-theme-dark` ); }' );
142 }
143 }
144
145 private function enqueue_assets() {
146 Plugin::$instance->init_common();
147
148 /** @var WebCLIModule $web_cli */
149 $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
150 $web_cli->register_scripts();
151
152 Plugin::$instance->common->register_scripts();
153
154 wp_register_style(
155 'select2',
156 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
157 [],
158 '4.0.6-rc.1'
159 );
160
161 Plugin::$instance->common->register_styles();
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' ) || 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 $this->add_component( 'onboarding', new Modules\Onboarding\Module() );
250
251 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
252 $this->register_admin_menu( $admin_menu );
253 }, Source_Local::ADMIN_MENU_PRIORITY + 10 );
254
255 // Happens after WP plugin page validation.
256 add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
257
258 if ( $this->is_current() ) {
259 add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
260 } else {
261 add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
262 }
263 }
264 }
265