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

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

271 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App;
3
4 use Elementor\App\AdminMenuItems\Theme_Builder_Menu_Item;
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Modules\WebCli\Module as WebCLIModule;
7 use Elementor\Core\Base\App as BaseApp;
8 use Elementor\Core\Settings\Manager as SettingsManager;
9 use Elementor\Plugin;
10 use Elementor\TemplateLibrary\Source_Local;
11 use Elementor\User;
12 use Elementor\Utils;
13 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 class App extends BaseApp {
20
21 const PAGE_ID = 'elementor-app';
22
23 /**
24 * Get module name.
25 *
26 * Retrieve the module name.
27 *
28 * @since 3.0.0
29 * @access public
30 *
31 * @return string Module name.
32 */
33 public function get_name() {
34 return 'app';
35 }
36
37 public function get_base_url() {
38 return admin_url( 'admin.php?page=' . self::PAGE_ID . '&ver=' . ELEMENTOR_VERSION );
39 }
40
41 private function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
42 $admin_menu->register( static::PAGE_ID, new Theme_Builder_Menu_Item() );
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 // Add the introduction and user settings only when it is needed (when loading the app and not in the editor or admin pages)
76 $this->set_settings( 'user', [
77 'introduction' => (object) User::get_introduction_meta(),
78 'is_administrator' => current_user_can( 'manage_options' ),
79 'restrictions' => Plugin::$instance->role_manager->get_user_restrictions_array(),
80 ] );
81
82 $this->enqueue_assets();
83
84 // Setup default heartbeat options
85 // TODO: Enable heartbeat.
86 add_filter( 'heartbeat_settings', function( $settings ) {
87 $settings['interval'] = 15;
88 return $settings;
89 } );
90
91 $this->render();
92 die;
93 }
94
95 protected function get_init_settings() {
96 $referer = wp_get_referer();
97
98 return [
99 'menu_url' => $this->get_base_url() . '#site-editor/promotion',
100 'assets_url' => ELEMENTOR_ASSETS_URL,
101 'pages_url' => admin_url( 'edit.php?post_type=page' ),
102 'return_url' => $referer ? $referer : admin_url(),
103 'hasPro' => Utils::has_pro(),
104 'admin_url' => admin_url(),
105 'login_url' => wp_login_url(),
106 'base_url' => $this->get_base_url(),
107 'promotion' => Filtered_Promotions_Manager::get_filtered_promotion_data(
108 [ 'upgrade_url' => 'https://go.elementor.com/go-pro-theme-builder/' ],
109 'elementor/site-editor/promotion',
110 'upgrade_url'
111 ),
112 ];
113 }
114
115 private function render() {
116 require __DIR__ . '/view.php';
117 }
118
119 /**
120 * Get Elementor editor theme color preference.
121 *
122 * Retrieve the user theme color preference as defined by editor preferences manager.
123 *
124 * @since 3.0.0
125 * @access private
126 *
127 * @return string Preferred editor theme.
128 */
129 private function get_elementor_ui_theme_preference() {
130 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
131
132 return $editor_preferences->get_model()->get_settings( 'ui_theme' );
133 }
134
135 /**
136 * Enqueue dark theme detection script.
137 *
138 * Enqueues an inline script that detects user-agent settings for dark mode and adds a complimentary class to the body tag.
139 *
140 * @since 3.0.0
141 * @access private
142 */
143 private function enqueue_dark_theme_detection_script() {
144 if ( 'auto' === $this->get_elementor_ui_theme_preference() ) {
145 wp_add_inline_script( 'elementor-app',
146 'if ( window.matchMedia && window.matchMedia( `(prefers-color-scheme: dark)` ).matches )
147 { document.body.classList.add( `eps-theme-dark` ); }' );
148 }
149 }
150
151 private function enqueue_assets() {
152 Plugin::$instance->init_common();
153
154 /** @var WebCLIModule $web_cli */
155 $web_cli = Plugin::$instance->modules_manager->get_modules( 'web-cli' );
156 $web_cli->register_scripts();
157
158 Plugin::$instance->common->register_scripts();
159
160 wp_register_style(
161 'select2',
162 $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ),
163 [],
164 '4.0.6-rc.1'
165 );
166
167 Plugin::$instance->common->register_styles();
168
169 wp_register_style(
170 'select2',
171 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2.css',
172 [],
173 '4.0.6-rc.1'
174 );
175
176 wp_enqueue_style(
177 'elementor-app',
178 $this->get_css_assets_url( 'app', null, 'default', true ),
179 [
180 'select2',
181 'elementor-icons',
182 'elementor-common',
183 'select2',
184 ],
185 ELEMENTOR_VERSION
186 );
187
188 wp_enqueue_script(
189 'elementor-app-packages',
190 $this->get_js_assets_url( 'app-packages' ),
191 [
192 'wp-i18n',
193 'react',
194 ],
195 ELEMENTOR_VERSION,
196 true
197 );
198
199 wp_register_script(
200 'select2',
201 $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ),
202 [
203 'jquery',
204 ],
205 '4.0.6-rc.1',
206 true
207 );
208
209 wp_enqueue_script(
210 'elementor-app',
211 $this->get_js_assets_url( 'app' ),
212 [
213 'wp-url',
214 'wp-i18n',
215 'react',
216 'react-dom',
217 'select2',
218 ],
219 ELEMENTOR_VERSION,
220 true
221 );
222
223 $this->enqueue_dark_theme_detection_script();
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' ) || 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 }
269 }
270 }
271