PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.0
Elementor Website Builder – more than just a page builder v3.0.0
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 / core / app / app.php

app.php in Elementor Website Builder – more than just a page builder 3.0.0, at core/app/app.php

213 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\App;
3
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;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class App extends BaseApp {
14
15 const PAGE_ID = 'elementor-app';
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 */
27 public function get_name() {
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 'react',
171 'react-dom',
172 ],
173 ELEMENTOR_VERSION,
174 true
175 );
176
177 $this->enqueue_dark_theme_detection_script();
178
179 wp_set_script_translations( 'elementor-app', 'elementor', ELEMENTOR_PATH . 'languages' );
180
181 $this->print_config();
182 }
183
184 public function enqueue_app_loader() {
185 wp_enqueue_script(
186 'elementor-app-loader',
187 $this->get_js_assets_url( 'app-loader' ),
188 [
189 'elementor-common',
190 ],
191 ELEMENTOR_VERSION,
192 true
193 );
194
195 $this->print_config( 'elementor-app-loader' );
196 }
197
198 public function __construct() {
199 $this->add_component( 'site-editor', new Modules\SiteEditor\Module() );
200
201 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 21 /* after Elementor page */ );
202
203 // Happens after WP plugin page validation.
204 add_filter( 'add_menu_classes', [ $this, 'fix_submenu' ] );
205
206 if ( $this->is_current() ) {
207 add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
208 } else {
209 add_action( 'elementor/common/after_register_scripts', [ $this, 'enqueue_app_loader' ] );
210 }
211 }
212 }
213