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