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

258 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\App;
3
4 use Elementor\App\AdminMenuItems\Theme_Builder_Menu_Item;
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Icons_Manager;
7 use Elementor\Modules\WebCli\Module as WebCLIModule;
8 use Elementor\Core\Base\App as BaseApp;
9 use Elementor\Core\Settings\Manager as SettingsManager;
10 use Elementor\Plugin;
11 use Elementor\TemplateLibrary\Source_Local;
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 $this->enqueue_assets();
75
76 // Setup default heartbeat options
77 // TODO: Enable heartbeat.
78 add_filter( 'heartbeat_settings', function( $settings ) {
79 $settings['interval'] = 15;
80 return $settings;
81 } );
82
83 $this->render();
84 die;
85 }
86
87 protected function get_init_settings() {
88 $referer = wp_get_referer();
89
90 return [
91 'menu_url' => $this->get_base_url() . '#site-editor/promotion',
92 'assets_url' => ELEMENTOR_ASSETS_URL,
93 'pages_url' => admin_url( 'edit.php?post_type=page' ),
94 'return_url' => $referer ? $referer : admin_url(),
95 'hasPro' => Utils::has_pro(),
96 'admin_url' => admin_url(),
97 'login_url' => wp_login_url(),
98 'base_url' => $this->get_base_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
141 /** @var WebCLIModule $web_cli */
142 $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
143 $web_cli->register_scripts();
144
145 Plugin::$instance->common->register_scripts();
146
147 wp_register_style(
148 'select2',
149 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
150 [],
151 '4.0.6-rc.1'
152 );
153
154 Plugin::$instance->common->register_styles();
155
156 wp_register_style(
157 'select2',
158 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
159 [],
160 '4.0.6-rc.1'
161 );
162
163 wp_enqueue_style(
164 'elementor-app',
165 $this->get_css_assets_url( 'app', null, 'default', true ),
166 [
167 'select2',
168 'elementor-icons',
169 'elementor-common',
170 'select2',
171 ],
172 ELEMENTOR_VERSION
173 );
174
175 wp_enqueue_script(
176 'elementor-app-packages',
177 $this->get_js_assets_url( 'app-packages' ),
178 [
179 'wp-i18n',
180 'react',
181 ],
182 ELEMENTOR_VERSION,
183 true
184 );
185
186 wp_register_script(
187 'select2',
188 $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
189 [
190 'jquery',
191 ],
192 '4.0.6-rc.1',
193 true
194 );
195
196 wp_enqueue_script(
197 'elementor-app',
198 $this->get_js_assets_url( 'app' ),
199 [
200 'wp-url',
201 'wp-i18n',
202 'react',
203 'react-dom',
204 'select2',
205 ],
206 ELEMENTOR_VERSION,
207 true
208 );
209
210 $this->enqueue_dark_theme_detection_script();
211
212 wp_set_script_translations( 'elementor-app-packages', 'elementor' );
213 wp_set_script_translations( 'elementor-app', 'elementor' );
214
215 $this->print_config();
216 }
217
218 public function enqueue_app_loader() {
219 wp_enqueue_script(
220 'elementor-app-loader',
221 $this->get_js_assets_url( 'app-loader' ),
222 [
223 'elementor-common',
224 ],
225 ELEMENTOR_VERSION,
226 true
227 );
228
229 $this->print_config( 'elementor-app-loader' );
230 }
231
232 public function __construct() {
233 $this->add_component( 'site-editor', new Modules\SiteEditor\Module() );
234
235 if ( current_user_can( 'manage_options' ) || Utils::is_wp_cli() ) {
236 $this->add_component( 'import-export', new Modules\ImportExport\Module() );
237
238 // Kit library is depended on import-export
239 $this->add_component( 'kit-library', new Modules\KitLibrary\Module() );
240 }
241
242 $this->add_component( 'onboarding', new Modules\Onboarding\Module() );
243
244 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
245 $this->register_admin_menu( $admin_menu );
246 }, Source_Local::ADMIN_MENU_PRIORITY + 10 );
247
248 // Happens after WP plugin page validation.
249 add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
250
251 if ( $this->is_current() ) {
252 add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
253 } else {
254 add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
255 }
256 }
257 }
258