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