PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.5
Elementor Website Builder – more than just a page builder v3.7.5
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
← All changes | core/app/app.php +254 -4 4.1.0-dev13.7.5 View file →
@@ -1,20 +1,270 @@
1 1 <?php
2 2 namespace Elementor\Core\App;
3 3
4 +use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
5 +use Elementor\Core\App\AdminMenuItems\Theme_Builder_Menu_Item;
6 +use Elementor\Icons_Manager;
7 +use Elementor\Modules\WebCli\Module as WebCLIModule;
4 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;
5 13
6 14 if ( ! defined( 'ABSPATH' ) ) {
7 15 exit; // Exit if accessed directly.
8 16 }
9 17
10 -/**
11 - * This App class was introduced for backwards compatibility with 3rd parties.
12 - */
13 18 class App extends BaseApp {
14 19
15 20 const PAGE_ID = 'elementor-app';
16 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 + */
17 32 public function get_name() {
18 - return 'app-bc';
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 + 'return_url' => $referer ? $referer : admin_url(),
94 + 'hasPro' => Utils::has_pro(),
95 + 'admin_url' => admin_url(),
96 + 'login_url' => wp_login_url(),
97 + 'base_url' => $this->get_base_url(),
98 + ];
99 + }
100 +
101 + private function render() {
102 + require __DIR__ . '/view.php';
103 + }
104 +
105 + /**
106 + * Get Elementor UI theme preference.
107 + *
108 + * Retrieve the user UI theme preference as defined by editor preferences manager.
109 + *
110 + * @since 3.0.0
111 + * @access private
112 + *
113 + * @return string Preferred UI theme.
114 + */
115 + private function get_elementor_ui_theme_preference() {
116 + $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
117 +
118 + return $editor_preferences->get_model()->get_settings( 'ui_theme' );
119 + }
120 +
121 + /**
122 + * Enqueue dark theme detection script.
123 + *
124 + * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
125 + *
126 + * @since 3.0.0
127 + * @access private
128 + */
129 + private function enqueue_dark_theme_detection_script() {
130 + if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
131 + wp_add_inline_script( 'elementor-app',
132 + 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
133 + { document.body.classList.add( `eps-theme-dark` ); }' );
134 + }
135 + }
136 +
137 + private function enqueue_assets() {
138 + Plugin::$instance->init_common();
139 +
140 + /** @var WebCLIModule $web_cli */
141 + $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
142 + $web_cli->register_scripts();
143 +
144 + Plugin::$instance->common->register_scripts();
145 +
146 + wp_register_style(
147 + 'select2',
148 + $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
149 + [],
150 + '4.0.6-rc.1'
151 + );
152 +
153 + wp_register_style(
154 + 'elementor-icons',
155 + $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
156 + [],
157 + Icons_Manager::ELEMENTOR_ICONS_VERSION
158 + );
159 +
160 + wp_register_style(
161 + 'elementor-common',
162 + $this->get_css_assets_url( 'common', null, 'default', true ),
163 + [],
164 + ELEMENTOR_VERSION
165 + );
166 +
167 + wp_register_style(
168 + 'select2',
169 + ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
170 + [],
171 + '4.0.6-rc.1'
172 + );
173 +
174 + wp_enqueue_style(
175 + 'elementor-app',
176 + $this->get_css_assets_url( 'app', null, 'default', true ),
177 + [
178 + 'select2',
179 + 'elementor-icons',
180 + 'elementor-common',
181 + 'select2',
182 + ],
183 + ELEMENTOR_VERSION
184 + );
185 +
186 + wp_enqueue_script(
187 + 'elementor-app-packages',
188 + $this->get_js_assets_url( 'app-packages' ),
189 + [
190 + 'wp-i18n',
191 + 'react',
192 + ],
193 + ELEMENTOR_VERSION,
194 + true
195 + );
196 +
197 + wp_register_script(
198 + 'select2',
199 + $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
200 + [
201 + 'jquery',
202 + ],
203 + '4.0.6-rc.1',
204 + true
205 + );
206 +
207 + wp_enqueue_script(
208 + 'elementor-app',
209 + $this->get_js_assets_url( 'app' ),
210 + [
211 + 'wp-url',
212 + 'wp-i18n',
213 + 'react',
214 + 'react-dom',
215 + 'select2',
216 + ],
217 + ELEMENTOR_VERSION,
218 + true
219 + );
220 +
221 + if ( ! $this->get_settings( 'disable_dark_theme' ) ) {
222 + $this->enqueue_dark_theme_detection_script();
223 + }
224 +
225 + wp_set_script_translations( 'elementor-app-packages', 'elementor' );
226 + wp_set_script_translations( 'elementor-app', 'elementor' );
227 +
228 + $this->print_config();
229 + }
230 +
231 + public function enqueue_app_loader() {
232 + wp_enqueue_script(
233 + 'elementor-app-loader',
234 + $this->get_js_assets_url( 'app-loader' ),
235 + [
236 + 'elementor-common',
237 + ],
238 + ELEMENTOR_VERSION,
239 + true
240 + );
241 +
242 + $this->print_config( 'elementor-app-loader' );
243 + }
244 +
245 + public function __construct() {
246 + $this->add_component( 'site-editor', new Modules\SiteEditor\Module() );
247 +
248 + if ( current_user_can( 'manage_options' ) && Plugin::$instance->experiments->is_feature_active( 'e_import_export' ) || Utils::is_wp_cli() ) {
249 + $this->add_component( 'import-export', new Modules\ImportExport\Module() );
250 +
251 + // Kit library is depended on import-export
252 + $this->add_component( 'kit-library', new Modules\KitLibrary\Module() );
253 + }
254 +
255 + $this->add_component( 'onboarding', new Modules\Onboarding\Module() );
256 +
257 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
258 + $this->register_admin_menu( $admin_menu );
259 + }, Source_Local::ADMIN_MENU_PRIORITY + 10 );
260 +
261 + // Happens after WP plugin page validation.
262 + add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
263 +
264 + if ( $this->is_current() ) {
265 + add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
266 + } else {
267 + add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
268 + }
19 269 }
20 270 }