PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.1
Elementor Website Builder – more than just a page builder v3.0.1
4.3.0-beta3 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 All 452 releases
← All changes | core/app/app.php +198 -4 4.2.0-dev23.0.1 View file →
@@ -1,20 +1,214 @@
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 + 'elementor-icons',
133 + $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
134 + [],
135 + '5.6.2'
136 + );
137 +
138 + wp_register_style(
139 + 'elementor-common',
140 + $this->get_css_assets_url( 'common', null, 'default', true ),
141 + [],
142 + ELEMENTOR_VERSION
143 + );
144 +
145 + wp_enqueue_style(
146 + 'elementor-app',
147 + $this->get_css_assets_url( 'app', null, 'default', true ),
148 + [
149 + 'elementor-icons',
150 + 'elementor-common',
151 + ],
152 + ELEMENTOR_VERSION
153 + );
154 +
155 + wp_enqueue_script(
156 + 'elementor-app-packages',
157 + $this->get_js_assets_url( 'app-packages' ),
158 + [
159 + 'wp-i18n',
160 + 'react',
161 + ],
162 + ELEMENTOR_VERSION,
163 + true
164 + );
165 +
166 + wp_enqueue_script(
167 + 'elementor-app',
168 + $this->get_js_assets_url( 'app' ),
169 + [
170 + 'wp-i18n',
171 + 'react',
172 + 'react-dom',
173 + ],
174 + ELEMENTOR_VERSION,
175 + true
176 + );
177 +
178 + $this->enqueue_dark_theme_detection_script();
179 +
180 + wp_set_script_translations( 'elementor-app-packages', 'elementor' );
181 + wp_set_script_translations( 'elementor-app', 'elementor' );
182 +
183 + $this->print_config();
184 + }
185 +
186 + public function enqueue_app_loader() {
187 + wp_enqueue_script(
188 + 'elementor-app-loader',
189 + $this->get_js_assets_url( 'app-loader' ),
190 + [
191 + 'elementor-common',
192 + ],
193 + ELEMENTOR_VERSION,
194 + true
195 + );
196 +
197 + $this->print_config( 'elementor-app-loader' );
198 + }
199 +
200 + public function __construct() {
201 + $this->add_component( 'site-editor', new Modules\SiteEditor\Module() );
202 +
203 + add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 21 /* after Elementor page */ );
204 +
205 + // Happens after WP plugin page validation.
206 + add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
207 +
208 + if ( $this->is_current() ) {
209 + add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
210 + } else {
211 + add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
212 + }
19 213 }
20 214 }