PluginProbe
Elementor Website Builder – more than just a page builder / 3.8.1
Elementor Website Builder – more than just a page builder v3.8.1
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 | app/modules/onboarding/module.php +381 -264 4.2.23.8.1 View file →
@@ -1,361 +1,478 @@
1 1 <?php
2 -
3 2 namespace Elementor\App\Modules\Onboarding;
4 3
5 -use Elementor\App\Modules\Onboarding\Data\Controller;
6 -use Elementor\App\Modules\Onboarding\Data\Endpoints\Install_Theme;
7 -use Elementor\App\Modules\Onboarding\Storage\Entities\User_Choices;
8 -use Elementor\App\Modules\Onboarding\Storage\Entities\User_Progress;
9 -use Elementor\App\Modules\Onboarding\Storage\Onboarding_Progress_Manager;
4 +use Automatic_Upgrader_Skin;
10 5 use Elementor\Core\Base\Module as BaseModule;
11 -use Elementor\Core\Settings\Manager as SettingsManager;
12 -use Elementor\Includes\EditorAssetsAPI;
6 +use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
7 +use Elementor\Core\Common\Modules\Connect\Apps\Library;
8 +use Elementor\Core\Files\Uploads_Manager;
13 9 use Elementor\Plugin;
14 -use Elementor\Utils;
10 +use Elementor\Tracker;
11 +use Plugin_Upgrader;
15 12
16 13 if ( ! defined( 'ABSPATH' ) ) {
17 - exit;
14 + exit; // Exit if accessed directly
18 15 }
19 16
17 +/**
18 + * Onboarding Module
19 + *
20 + * Responsible for initializing Elementor App functionality
21 + *
22 + * @since 3.6.0
23 + */
20 24 class Module extends BaseModule {
21 25
22 - const VERSION = '2.0.0';
23 - const ASSETS_BASE_URL = 'https://assets.elementor.com/onboarding/v1/strings/';
26 + const VERSION = '1.0.0';
24 27 const ONBOARDING_OPTION = 'elementor_onboarded';
25 28
26 - const SUPPORTED_LOCALES = [
27 - 'de_DE' => 'de',
28 - 'es_ES' => 'es',
29 - 'fr_FR' => 'fr',
30 - 'he_IL' => 'he',
31 - 'id_ID' => 'id',
32 - 'it_IT' => 'it',
33 - 'nl_NL' => 'nl',
34 - 'pl_PL' => 'pl',
35 - 'pt_BR' => 'pt',
36 - 'tr_TR' => 'tr',
37 - ];
38 -
39 - private Onboarding_Progress_Manager $progress_manager;
40 -
41 - public function get_name(): string {
29 + /**
30 + * Get name.
31 + *
32 + * @since 3.6.0
33 + * @access public
34 + *
35 + * @return string
36 + */
37 + public function get_name() {
42 38 return 'onboarding';
43 39 }
44 40
45 - public static function has_user_finished_onboarding(): bool {
46 - return (bool) get_option( self::ONBOARDING_OPTION );
47 - }
48 -
49 - public function __construct() {
50 - $this->progress_manager = Onboarding_Progress_Manager::instance();
51 -
52 - Plugin::instance()->data_manager_v2->register_controller( new Controller() );
53 -
54 - add_action( 'elementor/init', [ $this, 'on_elementor_init' ], 12 );
55 -
56 - if ( $this->should_show_starter() ) {
57 - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_starter_settings' ] );
58 - add_filter( 'elementor/editor/v2/packages', [ $this, 'add_starter_packages' ] );
59 - add_action( 'elementor/editor/v2/styles/enqueue', [ $this, 'enqueue_fonts' ] );
60 - add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_starter_preview_css' ] );
61 - }
62 - }
63 -
64 - public function on_elementor_init(): void {
65 - if ( ! Plugin::instance()->app->is_current() ) {
41 + /**
42 + * Set Onboarding Settings
43 + *
44 + * Creates an array of module settings that is localized into the JS App config.
45 + *
46 + * @since 3.6.0
47 + */
48 + private function set_onboarding_settings() {
49 + if ( ! Plugin::$instance->common ) {
66 50 return;
67 51 }
68 52
69 - $this->set_onboarding_settings();
70 - $this->enqueue_fonts();
71 - }
53 + // Get the published pages and posts
54 + $pages_and_posts = new \WP_Query( [
55 + 'post_type' => [ 'page', 'post' ],
56 + 'post_status' => 'publish',
57 + 'update_post_meta_cache' => false,
58 + 'update_post_term_cache' => false,
59 + 'no_found_rows' => true,
60 + ] );
72 61
73 - public function enqueue_fonts(): void {
74 - wp_enqueue_style(
75 - 'elementor-onboarding-fonts',
76 - 'https://fonts.googleapis.com/css2?family=Poppins:wght@500&display=swap',
77 - [],
78 - ELEMENTOR_VERSION
79 - );
80 - }
62 + $custom_site_logo_id = get_theme_mod( 'custom_logo' );
63 + $custom_logo_src = wp_get_attachment_image_src( $custom_site_logo_id, 'full' );
64 + $site_name = get_option( 'blogname', '' );
81 65
82 - public function enqueue_starter_preview_css(): void {
83 - $css = '
84 - #site-header,
85 - .page-header { display: var(--e-starter-header-display, none); }
86 - ';
66 + $hello_theme = wp_get_theme( 'hello-elementor' );
67 + $hello_theme_errors = is_object( $hello_theme->errors() ) ? $hello_theme->errors()->errors : [];
87 68
88 - wp_register_style( 'elementor-starter-preview', false );
89 - wp_enqueue_style( 'elementor-starter-preview' );
90 - wp_add_inline_style( 'elementor-starter-preview', $css );
91 - }
69 + /** @var Library $library */
70 + $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' );
92 71
93 - public function progress_manager(): Onboarding_Progress_Manager {
94 - return $this->progress_manager;
95 - }
96 -
97 - private function set_onboarding_settings(): void {
98 - if ( ! Plugin::instance()->common ) {
99 - return;
100 - }
101 -
102 - $progress = $this->progress_manager->get_progress();
103 - $choices = $this->progress_manager->get_choices();
104 - $steps = $this->get_steps_config();
105 -
106 - // If the user previously selected a theme but it's no longer the active theme,
107 - // clear the theme selection so the user can re-select.
108 - $this->maybe_invalidate_theme_selection( $progress, $choices );
109 -
110 - $is_connected = $this->is_user_connected();
111 -
112 72 Plugin::$instance->app->set_settings( 'onboarding', [
113 - 'version' => self::VERSION,
114 - 'restUrl' => rest_url( 'elementor/v1/onboarding/' ),
115 - 'nonce' => wp_create_nonce( 'wp_rest' ),
116 - 'progress' => $this->validate_progress_for_steps( $progress, $steps ),
117 - 'choices' => $choices->to_array(),
118 - 'hadUnexpectedExit' => $progress->had_unexpected_exit( self::has_user_finished_onboarding() ),
119 - 'isConnected' => $is_connected,
120 - 'userName' => $this->get_user_display_name(),
121 - 'steps' => $steps,
122 - 'uiTheme' => $this->get_ui_theme_preference(),
123 - 'translations' => $this->get_translated_strings(),
124 - 'shouldShowProInstallScreen' => $is_connected ? $this->should_show_pro_install_screen() : false,
73 + 'eventPlacement' => 'Onboarding wizard',
74 + 'onboardingAlreadyRan' => get_option( self::ONBOARDING_OPTION ),
75 + 'onboardingVersion' => self::VERSION,
76 + 'isLibraryConnected' => $library->is_connected(),
77 + // Used to check if the Hello Elementor theme is installed but not activated.
78 + 'helloInstalled' => empty( $hello_theme_errors['theme_not_found'] ),
79 + 'helloActivated' => 'hello-elementor' === get_option( 'template' ),
80 + // The "Use Hello theme on my site" checkbox should be checked by default only if this condition is met.
81 + 'helloOptOut' => count( $pages_and_posts->posts ) < 5,
82 + 'siteName' => esc_html( $site_name ),
83 + 'isUnfilteredFilesEnabled' => Uploads_Manager::are_unfiltered_uploads_enabled(),
125 84 'urls' => [
126 - 'dashboard' => admin_url(),
127 - 'editor' => admin_url( 'edit.php?post_type=elementor_library' ),
128 - 'connect' => $this->get_connect_url(),
129 - 'signUp' => $this->get_connect_url( 'signup' ),
130 - 'comparePlans' => 'https://go.elementor.com/go-pro-onboarding-editor-features-step-upgrade/',
85 + 'kitLibrary' => Plugin::$instance->app->get_base_url() . '#/kit-library?order[direction]=desc&order[by]=featuredIndex',
131 86 'createNewPage' => Plugin::$instance->documents->get_create_new_post_url(),
132 - 'upgradeUrl' => 'https://go.elementor.com/go-pro-onboarding-editor-header-upgrade/',
87 + 'connect' => $library->get_admin_url( 'authorize', [
88 + 'utm_source' => 'onboarding-wizard',
89 + 'utm_campaign' => 'connect-account',
90 + 'utm_medium' => 'wp-dash',
91 + 'utm_term' => self::VERSION,
92 + 'source' => 'generic',
93 + ] ),
94 + 'signUp' => $library->get_admin_url( 'authorize', [
95 + 'utm_source' => 'onboarding-wizard',
96 + 'utm_campaign' => 'connect-account',
97 + 'utm_medium' => 'wp-dash',
98 + 'utm_term' => self::VERSION,
99 + 'source' => 'generic',
100 + 'screen_hint' => 'signup',
101 + ] ),
102 + 'uploadPro' => Plugin::$instance->app->get_base_url() . '#/onboarding/uploadAndInstallPro?mode=popup',
133 103 ],
104 + 'siteLogo' => [
105 + 'id' => $custom_site_logo_id,
106 + 'url' => $custom_logo_src ? $custom_logo_src[0] : '',
107 + ],
108 + 'utms' => [
109 + 'connectTopBar' => '&utm_content=top-bar',
110 + 'connectCta' => '&utm_content=cta-button',
111 + 'connectCtaLink' => '&utm_content=cta-link',
112 + 'downloadPro' => '?utm_source=onboarding-wizard&utm_campaign=my-account-subscriptions&utm_medium=wp-dash&utm_content=import-pro-plugin&utm_term=' . self::VERSION,
113 + ],
114 + 'nonce' => wp_create_nonce( 'onboarding' ),
134 115 ] );
135 116 }
136 117
137 - private function validate_progress_for_steps( User_Progress $progress, array $steps ): array {
138 - $progress_data = $progress->to_array();
139 - $step_count = count( $steps );
140 - $current_step_index = $progress->get_current_step_index() ?? 0;
141 - $current_step_id = $progress->get_current_step_id() ?? $steps[0]['id'] ?? 'building_for';
118 + /**
119 + * Get Permission Error Response
120 + *
121 + * Returns the response that is returned when the user's capabilities are not sufficient for performing an action.
122 + *
123 + * @since 3.6.4
124 + *
125 + * @return array
126 + */
127 + private function get_permission_error_response() {
128 + return [
129 + 'status' => 'error',
130 + 'payload' => [
131 + 'error_message' => esc_html__( 'you are not allowed to perform this action', 'elementor' ),
132 + ],
133 + ];
134 + }
142 135
143 - $is_invalid_step_index = $current_step_index < 0 || $current_step_index >= $step_count;
136 + /**
137 + * Maybe Update Site Logo
138 + *
139 + * If a new name is provided, it will be updated as the Site Name.
140 + *
141 + * @since 3.6.0
142 + *
143 + * @return array
144 + */
145 + private function maybe_update_site_name() {
146 + $problem_error = [
147 + 'status' => 'error',
148 + 'payload' => [
149 + 'error_message' => esc_html__( 'There was a problem setting your site name', 'elementor' ),
150 + ],
151 + ];
144 152
145 - if ( $is_invalid_step_index ) {
146 - $current_step_id = $steps[0]['id'];
147 - $current_step_index = 0;
153 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
154 + if ( empty( $_POST['data'] ) ) {
155 + return $problem_error;
148 156 }
149 157
150 - $progress_data['current_step_id'] = $current_step_id;
151 - $progress_data['current_step_index'] = $current_step_index;
158 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
159 + $data = json_decode( stripslashes( $_POST['data'] ), true );
152 160
153 - return $progress_data;
154 - }
161 + if ( ! isset( $data['siteName'] ) ) {
162 + return $problem_error;
163 + }
155 164
156 - private function is_user_connected(): bool {
157 - $library = $this->get_library_app();
165 + /**
166 + * Onboarding Site Name
167 + *
168 + * Filters the new site name passed by the user to update in Elementor's onboarding process.
169 + * Elementor runs `esc_html()` on the Site Name passed by the user for security reasons. If a user wants to
170 + * include special characters in their site name, they can use this filter to override it.
171 + *
172 + * @since 3.6.0
173 + *
174 + * @param string Escaped new site name
175 + */
176 + $new_site_name = apply_filters( 'elementor/onboarding/site-name', $data['siteName'] );
158 177
159 - return $library ? $library->is_connected() : false;
178 + // The site name is sanitized in `update_options()`
179 + update_option( 'blogname', $new_site_name );
180 +
181 + return [
182 + 'status' => 'success',
183 + 'payload' => [
184 + 'siteNameUpdated' => true,
185 + ],
186 + ];
160 187 }
161 188
162 - private function get_connect_url( string $screen_hint = '' ): string {
163 - $library = $this->get_library_app();
164 -
165 - if ( ! $library ) {
166 - return '';
189 + /**
190 + * Maybe Update Site Logo
191 + *
192 + * If an image attachment ID is provided, it will be updated as the Site Logo Theme Mod.
193 + *
194 + * @since 3.6.0
195 + *
196 + * @return array
197 + */
198 + private function maybe_update_site_logo() {
199 + if ( ! current_user_can( 'edit_theme_options' ) ) {
200 + return $this->get_permission_error_response();
167 201 }
168 202
169 - return $library->get_admin_url( 'authorize', [
170 - 'utm_source' => 'onboarding-wizard',
171 - 'utm_campaign' => 'connect-account',
172 - 'utm_medium' => 'wp-dash',
173 - 'utm_term' => self::VERSION,
174 - 'source' => 'generic',
175 - 'screen_hint' => $screen_hint,
176 - ] ) ?? '';
177 - }
203 + $data_error = [
204 + 'status' => 'error',
205 + 'payload' => [
206 + 'error_message' => esc_html__( 'There was a problem setting your site logo', 'elementor' ),
207 + ],
208 + ];
178 209
179 - private function get_library_app() {
180 - $connect = Plugin::instance()->common->get_component( 'connect' );
181 -
182 - if ( ! $connect ) {
183 - return null;
210 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
211 + if ( empty( $_POST['data'] ) ) {
212 + return $data_error;
184 213 }
185 214
186 - return $connect->get_app( 'library' );
187 - }
215 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
216 + $data = json_decode( stripslashes( $_POST['data'] ), true );
188 217
189 - public static function should_show_pro_install_screen(): bool {
190 - if ( self::is_elementor_pro_installed() ) {
191 - return false;
218 + // If there is no attachment ID passed or it is not a valid ID, exit here.
219 + if ( empty( $data['attachmentId'] ) ) {
220 + return $data_error;
192 221 }
193 222
194 - $connect = Plugin::$instance->common->get_component( 'connect' );
223 + $absint_attachment_id = absint( $data['attachmentId'] );
195 224
196 - if ( ! $connect ) {
197 - return false;
225 + if ( 0 === $absint_attachment_id ) {
226 + return $data_error;
198 227 }
199 228
200 - $pro_install_app = $connect->get_app( 'pro-install' );
229 + $attachment_url = wp_get_attachment_url( $data['attachmentId'] );
201 230
202 - if ( ! $pro_install_app || ! $pro_install_app->is_connected() ) {
203 - return false;
231 + // Check if the attachment exists. If it does not, exit here.
232 + if ( ! $attachment_url ) {
233 + return $data_error;
204 234 }
205 235
206 - $download_link = $pro_install_app->get_download_link();
236 + set_theme_mod( 'custom_logo', $absint_attachment_id );
207 237
208 - return ! empty( $download_link );
238 + return [
239 + 'status' => 'success',
240 + 'payload' => [
241 + 'siteLogoUpdated' => true,
242 + ],
243 + ];
209 244 }
210 245
211 - private function get_ui_theme_preference(): string {
212 - $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
246 + /**
247 + * Maybe Upload Logo Image
248 + *
249 + * If an image file upload is provided, and it passes validation, it will be uploaded to the site's Media Library.
250 + *
251 + * @since 3.6.0
252 + *
253 + * @return array
254 + */
255 + private function maybe_upload_logo_image() {
256 + $error_message = esc_html__( 'There was a problem uploading your file', 'elementor' );
213 257
214 - $ui_theme = $editor_preferences->get_model()->get_settings( 'ui_theme' );
258 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
259 + if ( empty( $_FILES['fileToUpload'] ) || ! is_array( $_FILES['fileToUpload'] ) ) {
260 + return [
261 + 'status' => 'error',
262 + 'payload' => [
263 + 'error_message' => $error_message,
264 + ],
265 + ];
266 + }
215 267
216 - return $ui_theme ? $ui_theme : 'auto';
217 - }
268 + // If the user has allowed it, set the Request's state as an "Elementor Upload" request, in order to add
269 + // support for non-standard file uploads.
270 + if ( 'image/svg+xml' === $_FILES['fileToUpload']['type'] ) {
271 + if ( Uploads_Manager::are_unfiltered_uploads_enabled() ) {
272 + Plugin::$instance->uploads_manager->set_elementor_upload_state( true );
273 + } else {
274 + wp_send_json_error( 'To upload SVG files, you must allow uploading unfiltered files.' );
275 + }
276 + }
218 277
219 - private function get_user_display_name(): string {
220 - $library = $this->get_library_app();
278 + // If the image is an SVG file, sanitation is performed during the import (upload) process.
279 + $image_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( $_FILES['fileToUpload'] );
221 280
222 - if ( ! $library || ! $library->is_connected() ) {
223 - return '';
281 + if ( 'image/svg+xml' === $_FILES['fileToUpload']['type'] && Uploads_Manager::are_unfiltered_uploads_enabled() ) {
282 + // Reset Upload state.
283 + Plugin::$instance->uploads_manager->set_elementor_upload_state( false );
224 284 }
225 285
226 - $user = $library->get( 'user' );
286 + if ( $image_attachment && ! is_wp_error( $image_attachment ) ) {
287 + $result = [
288 + 'status' => 'success',
289 + 'payload' => [
290 + 'imageAttachment' => $image_attachment,
291 + ],
292 + ];
293 + } else {
294 + $result = [
295 + 'status' => 'error',
296 + 'payload' => [
297 + 'error_message' => $error_message,
298 + ],
299 + ];
300 + }
227 301
228 - return $user->first_name ?? '';
302 + return $result;
229 303 }
230 304
231 - public function should_show_starter(): bool {
232 - $progress = $this->progress_manager->get_progress();
305 + /**
306 + * Activate Hello Theme
307 + *
308 + * @since 3.6.0
309 + *
310 + * @return array
311 + */
312 + private function maybe_activate_hello_theme() {
313 + if ( ! current_user_can( 'switch_themes' ) ) {
314 + return $this->get_permission_error_response();
315 + }
233 316
234 - return self::VERSION === get_option( self::ONBOARDING_OPTION ) && ! $progress->is_starter_dismissed();
235 - }
317 + switch_theme( 'hello-elementor' );
236 318
237 - public function add_starter_packages( array $packages ): array {
238 - $packages[] = 'editor-starter';
239 -
240 - return $packages;
241 - }
242 -
243 - public function add_starter_settings( array $settings ): array {
244 - $settings['starter'] = [
245 - 'restPath' => 'elementor/v1/onboarding/user-progress',
246 - 'aiPlannerUrl' => 'https://planner.elementor.com/home.html',
247 - 'kitLibraryUrl' => Plugin::$instance->app->get_base_url() . '#/kit-library',
319 + return [
320 + 'status' => 'success',
321 + 'payload' => [
322 + 'helloThemeActivated' => true,
323 + ],
248 324 ];
249 -
250 - return $settings;
251 325 }
252 326
253 - private function maybe_invalidate_theme_selection( User_Progress $progress, User_Choices $choices ): void {
254 - $selected_theme = $choices->get_theme_selection();
255 -
256 - if ( empty( $selected_theme ) ) {
257 - return;
327 + /**
328 + * Upload and Install Elementor Pro
329 + *
330 + * @since 3.6.0
331 + *
332 + * @return array
333 + */
334 + private function upload_and_install_pro() {
335 + if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) ) {
336 + return $this->get_permission_error_response();
258 337 }
259 338
260 - $active_theme = get_stylesheet();
339 + $error_message = esc_html__( 'There was a problem uploading your file', 'elementor' );
261 340
262 - if ( $active_theme !== $selected_theme ) {
263 - $completed = $this->filter_out_theme_selection_step( $progress->get_completed_steps() );
264 - $progress->set_completed_steps( $completed );
265 - $this->progress_manager->save_progress( $progress );
266 -
267 - $choices->set_theme_selection( null );
268 - $this->progress_manager->save_choices( $choices );
341 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
342 + if ( empty( $_FILES['fileToUpload'] ) || ! is_array( $_FILES['fileToUpload'] ) ) {
343 + return [
344 + 'status' => 'error',
345 + 'payload' => [
346 + 'error_message' => $error_message,
347 + ],
348 + ];
269 349 }
270 - }
271 350
272 - private function filter_out_theme_selection_step( array $steps ): array {
273 - return array_values( array_filter( $steps, function ( $step ) {
274 - return 'theme_selection' !== $step;
275 - } ) );
276 - }
351 + $result = [];
277 352
278 - private function get_translated_strings(): array {
279 - $locale = $this->get_onboarding_locale();
353 + if ( ! class_exists( 'Automatic_Upgrader_Skin' ) ) {
354 + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
355 + }
280 356
281 - $api = new EditorAssetsAPI( [
282 - EditorAssetsAPI::ASSETS_DATA_URL => self::ASSETS_BASE_URL . $locale . '.json',
283 - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_onboarding_strings_' . $locale,
284 - EditorAssetsAPI::ASSETS_DATA_KEY => 'translations',
285 - ] );
357 + $skin = new Automatic_Upgrader_Skin();
358 + $upgrader = new Plugin_Upgrader( $skin );
359 + $upload_result = $upgrader->install( $_FILES['fileToUpload']['tmp_name'], [ 'overwrite_package' => false ] );
286 360
287 - return $api->get_assets_data();
288 - }
361 + if ( ! $upload_result || is_wp_error( $upload_result ) ) {
362 + $result = [
363 + 'status' => 'error',
364 + 'payload' => [
365 + 'error_message' => $error_message,
366 + ],
367 + ];
368 + } else {
369 + $activated = activate_plugin( WP_PLUGIN_DIR . '/elementor-pro/elementor-pro.php', false, false, true );
289 370
290 - private function get_onboarding_locale(): string {
291 - static $flipped_locales = null;
292 -
293 - if ( null === $flipped_locales ) {
294 - $flipped_locales = array_flip( self::SUPPORTED_LOCALES );
371 + if ( ! is_wp_error( $activated ) ) {
372 + $result = [
373 + 'status' => 'success',
374 + 'payload' => [
375 + 'elementorProInstalled' => true,
376 + ],
377 + ];
378 + } else {
379 + $result = [
380 + 'status' => 'error',
381 + 'payload' => [
382 + 'error_message' => $error_message,
383 + 'elementorProInstalled' => false,
384 + ],
385 + ];
386 + }
295 387 }
296 388
297 - $user_locale = get_user_locale();
389 + return $result;
390 + }
298 391
299 - if ( isset( self::SUPPORTED_LOCALES[ $user_locale ] ) ) {
300 - return $user_locale;
301 - }
392 + private function maybe_update_onboarding_db_option() {
393 + $db_option = get_option( self::ONBOARDING_OPTION );
302 394
303 - $locale = substr( $user_locale, 0, 2 );
304 -
305 - if ( isset( $flipped_locales[ $locale ] ) ) {
306 - return $flipped_locales[ $locale ];
395 + if ( ! $db_option ) {
396 + update_option( self::ONBOARDING_OPTION, true );
307 397 }
308 398
309 - return 'en';
399 + return [
400 + 'status' => 'success',
401 + 'payload' => 'onboarding DB',
402 + ];
310 403 }
311 404
312 - private function get_steps_config(): array {
313 - $steps = [
314 - [
315 - 'id' => 'building_for',
316 - 'label' => __( 'Who are you building for?', 'elementor' ),
317 - 'type' => 'single',
318 - ],
319 - [
320 - 'id' => 'site_about',
321 - 'label' => __( 'What is your site about?', 'elementor' ),
322 - 'type' => 'multiple',
323 - ],
324 - [
325 - 'id' => 'experience_level',
326 - 'label' => __( 'How much experience do you have with Elementor?', 'elementor' ),
327 - 'type' => 'single',
328 - ],
329 - ];
405 + /**
406 + * Maybe Handle Ajax
407 + *
408 + * This method checks if there are any AJAX actions being
409 + * @since 3.6.0
410 + *
411 + * @return array|null
412 + */
413 + private function maybe_handle_ajax() {
414 + $result = [];
330 415
331 - if ( ! $this->is_elementor_theme_active() ) {
332 - $steps[] = [
333 - 'id' => 'theme_selection',
334 - 'label' => __( 'Start with a theme that fits your needs', 'elementor' ),
335 - 'type' => 'single',
336 - ];
416 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
417 + switch ( $_POST['action'] ) {
418 + case 'elementor_update_site_name':
419 + // If no value is passed for any reason, no need ot update the site name.
420 + $result = $this->maybe_update_site_name();
421 + break;
422 + case 'elementor_update_site_logo':
423 + $result = $this->maybe_update_site_logo();
424 + break;
425 + case 'elementor_upload_site_logo':
426 + $result = $this->maybe_upload_logo_image();
427 + break;
428 + case 'elementor_activate_hello_theme':
429 + $result = $this->maybe_activate_hello_theme();
430 + break;
431 + case 'elementor_upload_and_install_pro':
432 + $result = $this->upload_and_install_pro();
433 + break;
434 + case 'elementor_update_onboarding_option':
435 + $result = $this->maybe_update_onboarding_db_option();
337 436 }
338 437
339 - if ( ! self::is_elementor_pro_installed() ) {
340 - $steps[] = [
341 - 'id' => 'site_features',
342 - 'label' => __( 'What do you want to include in your site?', 'elementor' ),
343 - 'type' => 'multiple',
344 - ];
438 + if ( ! empty( $result ) ) {
439 + if ( 'success' === $result['status'] ) {
440 + wp_send_json_success( $result['payload'] );
441 + } else {
442 + wp_send_json_error( $result['payload'] );
443 + }
345 444 }
445 + }
346 446
347 - return apply_filters( 'elementor/onboarding/steps', $steps );
348 - }
447 + public function __construct() {
448 + add_action( 'elementor/init', function() {
449 + // Only load when viewing the onboarding app.
450 + if ( Plugin::$instance->app->is_current() ) {
451 + $this->set_onboarding_settings();
452 + // Needed for installing the Hello Elementor theme.
453 + wp_enqueue_script( 'updates' );
454 + // Needed for uploading Logo from WP Media Library.
455 + wp_enqueue_media();
349 456
350 - private static function is_elementor_pro_installed(): bool {
351 - $is_pro_installed = Utils::has_pro() || Utils::is_pro_installed_and_not_active();
352 - return (bool) apply_filters( 'elementor/onboarding/is_elementor_pro_installed', $is_pro_installed );
353 - }
457 + Plugin::$instance->app->set_settings( 'disable_dark_theme', true );
458 + }
459 + }, 12 );
354 460
355 - private function is_elementor_theme_active(): bool {
356 - $active_theme = get_stylesheet();
357 - $is_active = in_array( $active_theme, Install_Theme::ALLOWED_THEMES, true );
461 + // Needed for uploading Logo from WP Media Library. The 'admin_menu' hook is used because it runs before
462 + // 'admin_init', and the App triggers printing footer scripts on 'admin_init' at priority 0.
463 + add_action( 'admin_menu', function() {
464 + add_action( 'wp_print_footer_scripts', 'wp_print_media_templates' );
465 + } );
358 466
359 - return (bool) apply_filters( 'elementor/onboarding/is_elementor_theme_active', $is_active );
467 + add_action( 'admin_init', function() {
468 + if ( wp_doing_ajax() &&
469 + isset( $_POST['action'] ) &&
470 + isset( $_POST['_nonce'] ) &&
471 + wp_verify_nonce( $_POST['_nonce'], Ajax::NONCE_KEY ) &&
472 + current_user_can( 'manage_options' )
473 + ) {
474 + $this->maybe_handle_ajax();
475 + }
476 + } );
360 477 }
361 478 }