| @@ -5,15 +5,14 @@ | ||
| 5 | 5 | use Elementor\Core\Base\Module as BaseModule; |
| 6 | 6 | use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 7 | 7 | use Elementor\Core\Common\Modules\Connect\Apps\Library; |
| 8 | 8 | use Elementor\Core\Files\Uploads_Manager; |
| 9 | -use Elementor\Includes\EditorAssetsAPI; | |
| 10 | 9 | use Elementor\Plugin; |
| 11 | -use Elementor\Utils; | |
| 10 | +use Elementor\Tracker; | |
| 12 | 11 | use Plugin_Upgrader; |
| 13 | 12 | |
| 14 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | - exit; // Exit if accessed directly. | |
| 14 | + exit; // Exit if accessed directly | |
| 16 | 15 | } |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | 18 | * Onboarding Module |
| @@ -26,16 +25,8 @@ | ||
| 26 | 25 | |
| 27 | 26 | const VERSION = '1.0.0'; |
| 28 | 27 | const ONBOARDING_OPTION = 'elementor_onboarded'; |
| 29 | 28 | |
| 30 | - const EXPERIMENT_EMPHASIZE_CONNECT_BENEFITS = 'emphasizeConnectBenefits101'; | |
| 31 | - const EXPERIMENT_OFFER_THEME_CHOICES_HELLO_BIZ = 'offerThemeChoicesHelloBiz201'; | |
| 32 | - const EXPERIMENT_EMPHASIZE_THEME_VALUE_AUDIENCE_202 = 'emphasizeThemeValueAudience202'; | |
| 33 | - const EXPERIMENT_UPDATE_COPY_VISUALS = 'updateCopyVisuals401'; | |
| 34 | - const EXPERIMENT_REDUCE_HIERARCHY_BLANK_OPTION = 'reduceHierarchyBlankOption402'; | |
| 35 | - | |
| 36 | - private ?API $editor_assets_api = null; | |
| 37 | - | |
| 38 | 29 | /** |
| 39 | 30 | * Get name. |
| 40 | 31 | * |
| 41 | 32 | * @since 3.6.0 |
| @@ -46,44 +37,8 @@ | ||
| 46 | 37 | public function get_name() { |
| 47 | 38 | return 'onboarding'; |
| 48 | 39 | } |
| 49 | 40 | |
| 50 | - private function is_experiment_enabled( string $experiment_key ) { | |
| 51 | - $editor_assets_api = $this->get_editor_assets_api(); | |
| 52 | - | |
| 53 | - if ( null === $editor_assets_api ) { | |
| 54 | - return false; | |
| 55 | - } | |
| 56 | - | |
| 57 | - return $editor_assets_api->is_experiment_enabled( $experiment_key ); | |
| 58 | - } | |
| 59 | - | |
| 60 | - private function is_hello_theme_activated(): bool { | |
| 61 | - $current_theme = get_option( 'template' ); | |
| 62 | - $hello_theme_variants = [ 'hello-elementor', 'hello-biz', 'hello-commerce', 'hello-theme' ]; | |
| 63 | - | |
| 64 | - return in_array( $current_theme, $hello_theme_variants, true ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - private function get_editor_assets_api(): ?API { | |
| 68 | - if ( null !== $this->editor_assets_api ) { | |
| 69 | - return $this->editor_assets_api; | |
| 70 | - } | |
| 71 | - | |
| 72 | - $editor_assets_api_instance = new EditorAssetsAPI( $this->get_editor_assets_api_config() ); | |
| 73 | - $this->editor_assets_api = new API( $editor_assets_api_instance ); | |
| 74 | - | |
| 75 | - return $this->editor_assets_api; | |
| 76 | - } | |
| 77 | - | |
| 78 | - private function get_editor_assets_api_config(): array { | |
| 79 | - return [ | |
| 80 | - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/ab-testing/v1/ab-testing.json', | |
| 81 | - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_ab_testing_data', | |
| 82 | - EditorAssetsAPI::ASSETS_DATA_KEY => 'ab-testing', | |
| 83 | - ]; | |
| 84 | - } | |
| 85 | - | |
| 86 | 41 | /** |
| 87 | 42 | * Set Onboarding Settings |
| 88 | 43 | * |
| 89 | 44 | * Creates an array of module settings that is localized into the JS App config. |
| @@ -112,9 +67,8 @@ | ||
| 112 | 67 | $hello_theme_errors = is_object( $hello_theme->errors() ) ? $hello_theme->errors()->errors : []; |
| 113 | 68 | |
| 114 | 69 | /** @var Library $library */ |
| 115 | 70 | $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' ); |
| 116 | - $is_editor_one_active = Plugin::$instance->experiments->is_feature_active( 'e_editor_one' ); | |
| 117 | 71 | |
| 118 | 72 | Plugin::$instance->app->set_settings( 'onboarding', [ |
| 119 | 73 | 'eventPlacement' => 'Onboarding wizard', |
| 120 | 74 | 'onboardingAlreadyRan' => get_option( self::ONBOARDING_OPTION ), |
| @@ -121,23 +75,15 @@ | ||
| 121 | 75 | 'onboardingVersion' => self::VERSION, |
| 122 | 76 | 'isLibraryConnected' => $library->is_connected(), |
| 123 | 77 | // Used to check if the Hello Elementor theme is installed but not activated. |
| 124 | 78 | 'helloInstalled' => empty( $hello_theme_errors['theme_not_found'] ), |
| 125 | - 'helloActivated' => $this->is_hello_theme_activated(), | |
| 79 | + 'helloActivated' => 'hello-elementor' === get_option( 'template' ), | |
| 126 | 80 | // The "Use Hello theme on my site" checkbox should be checked by default only if this condition is met. |
| 127 | 81 | 'helloOptOut' => count( $pages_and_posts->posts ) < 5, |
| 128 | 82 | 'siteName' => esc_html( $site_name ), |
| 129 | 83 | 'isUnfilteredFilesEnabled' => Uploads_Manager::are_unfiltered_uploads_enabled(), |
| 130 | - 'isEditorOneActive' => $is_editor_one_active, | |
| 131 | 84 | 'urls' => [ |
| 132 | - 'kitLibrary' => Plugin::$instance->app->get_base_url() . '&source=onboarding#/kit-library?order[direction]=desc&order[by]=featuredIndex', | |
| 133 | - 'sitePlanner' => add_query_arg( [ | |
| 134 | - 'type' => 'editor', | |
| 135 | - 'siteUrl' => esc_url( home_url() ), | |
| 136 | - 'siteName' => esc_html( $site_name ), | |
| 137 | - 'siteDescription' => esc_html( get_bloginfo( 'description' ) ), | |
| 138 | - 'siteLanguage' => get_locale(), | |
| 139 | - ], 'https://planner.elementor.com/onboarding.html' ), | |
| 85 | + 'kitLibrary' => Plugin::$instance->app->get_base_url() . '#/kit-library?order[direction]=desc&order[by]=featuredIndex', | |
| 140 | 86 | 'createNewPage' => Plugin::$instance->documents->get_create_new_post_url(), |
| 141 | 87 | 'connect' => $library->get_admin_url( 'authorize', [ |
| 142 | 88 | 'utm_source' => 'onboarding-wizard', |
| 143 | 89 | 'utm_campaign' => 'connect-account', |
| @@ -144,9 +90,8 @@ | ||
| 144 | 90 | 'utm_medium' => 'wp-dash', |
| 145 | 91 | 'utm_term' => self::VERSION, |
| 146 | 92 | 'source' => 'generic', |
| 147 | 93 | ] ), |
| 148 | - 'upgrade' => 'https://go.elementor.com/go-pro-onboarding-wizard-upgrade/', | |
| 149 | 94 | 'signUp' => $library->get_admin_url( 'authorize', [ |
| 150 | 95 | 'utm_source' => 'onboarding-wizard', |
| 151 | 96 | 'utm_campaign' => 'connect-account', |
| 152 | 97 | 'utm_medium' => 'wp-dash', |
| @@ -166,23 +111,8 @@ | ||
| 166 | 111 | 'connectCtaLink' => '&utm_content=cta-link', |
| 167 | 112 | 'downloadPro' => '?utm_source=onboarding-wizard&utm_campaign=my-account-subscriptions&utm_medium=wp-dash&utm_content=import-pro-plugin&utm_term=' . self::VERSION, |
| 168 | 113 | ], |
| 169 | 114 | 'nonce' => wp_create_nonce( 'onboarding' ), |
| 170 | - 'experiment' => true, | |
| 171 | - 'isExperiment101Enabled' => $this->is_experiment_enabled( self::EXPERIMENT_EMPHASIZE_CONNECT_BENEFITS ), | |
| 172 | - 'isExperiment201Enabled' => $this->is_experiment_enabled( self::EXPERIMENT_OFFER_THEME_CHOICES_HELLO_BIZ ), | |
| 173 | - 'isExperiment202Enabled' => $this->is_experiment_enabled( self::EXPERIMENT_EMPHASIZE_THEME_VALUE_AUDIENCE_202 ), | |
| 174 | - 'isExperiment401Enabled' => $this->is_experiment_enabled( self::EXPERIMENT_UPDATE_COPY_VISUALS ), | |
| 175 | - 'isExperiment402Enabled' => $this->is_experiment_enabled( self::EXPERIMENT_REDUCE_HIERARCHY_BLANK_OPTION ), | |
| 176 | - 'experimentNames' => [ | |
| 177 | - '101' => self::EXPERIMENT_EMPHASIZE_CONNECT_BENEFITS, | |
| 178 | - '201' => self::EXPERIMENT_OFFER_THEME_CHOICES_HELLO_BIZ, | |
| 179 | - '202' => self::EXPERIMENT_EMPHASIZE_THEME_VALUE_AUDIENCE_202, | |
| 180 | - '401' => self::EXPERIMENT_UPDATE_COPY_VISUALS, | |
| 181 | - '402' => self::EXPERIMENT_REDUCE_HIERARCHY_BLANK_OPTION, | |
| 182 | - ], | |
| 183 | - 'pageSubheading' => $is_editor_one_active ? __( 'Choose the capabilities you need to bring your vision to life', 'elementor' ) : __( 'Which Elementor Pro features do you need to bring your creative vision to life?', 'elementor' ), | |
| 184 | - 'pageHeading' => $is_editor_one_active ? __( ' Elevate your website with additional features.', 'elementor' ) : __( 'Elevate your website with additional Pro features.', 'elementor' ), | |
| 185 | 115 | ] ); |
| 186 | 116 | } |
| 187 | 117 | |
| 188 | 118 | /** |
| @@ -197,9 +127,9 @@ | ||
| 197 | 127 | private function get_permission_error_response() { |
| 198 | 128 | return [ |
| 199 | 129 | 'status' => 'error', |
| 200 | 130 | 'payload' => [ |
| 201 | - 'error_message' => esc_html__( 'You do not have permission to perform this action.', 'elementor' ), | |
| 131 | + 'error_message' => esc_html__( 'you are not allowed to perform this action', 'elementor' ), | |
| 202 | 132 | ], |
| 203 | 133 | ]; |
| 204 | 134 | } |
| 205 | 135 | |
| @@ -215,9 +145,9 @@ | ||
| 215 | 145 | private function maybe_update_site_name() { |
| 216 | 146 | $problem_error = [ |
| 217 | 147 | 'status' => 'error', |
| 218 | 148 | 'payload' => [ |
| 219 | - 'error_message' => esc_html__( 'There was a problem setting your site name.', 'elementor' ), | |
| 149 | + 'error_message' => esc_html__( 'There was a problem setting your site name', 'elementor' ), | |
| 220 | 150 | ], |
| 221 | 151 | ]; |
| 222 | 152 | |
| 223 | 153 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -225,9 +155,9 @@ | ||
| 225 | 155 | return $problem_error; |
| 226 | 156 | } |
| 227 | 157 | |
| 228 | 158 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 229 | - $data = json_decode( Utils::get_super_global_value( $_POST, 'data' ), true ); | |
| 159 | + $data = json_decode( stripslashes( $_POST['data'] ), true ); | |
| 230 | 160 | |
| 231 | 161 | if ( ! isset( $data['siteName'] ) ) { |
| 232 | 162 | return $problem_error; |
| 233 | 163 | } |
| @@ -272,9 +202,9 @@ | ||
| 272 | 202 | |
| 273 | 203 | $data_error = [ |
| 274 | 204 | 'status' => 'error', |
| 275 | 205 | 'payload' => [ |
| 276 | - 'error_message' => esc_html__( 'There was a problem setting your site logo.', 'elementor' ), | |
| 206 | + 'error_message' => esc_html__( 'There was a problem setting your site logo', 'elementor' ), | |
| 277 | 207 | ], |
| 278 | 208 | ]; |
| 279 | 209 | |
| 280 | 210 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -282,9 +212,9 @@ | ||
| 282 | 212 | return $data_error; |
| 283 | 213 | } |
| 284 | 214 | |
| 285 | 215 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 286 | - $data = json_decode( Utils::get_super_global_value( $_POST, 'data' ), true ); | |
| 216 | + $data = json_decode( stripslashes( $_POST['data'] ), true ); | |
| 287 | 217 | |
| 288 | 218 | // If there is no attachment ID passed or it is not a valid ID, exit here. |
| 289 | 219 | if ( empty( $data['attachmentId'] ) ) { |
| 290 | 220 | return $data_error; |
| @@ -322,14 +252,12 @@ | ||
| 322 | 252 | * |
| 323 | 253 | * @return array |
| 324 | 254 | */ |
| 325 | 255 | private function maybe_upload_logo_image() { |
| 326 | - $error_message = esc_html__( 'There was a problem uploading your file.', 'elementor' ); | |
| 256 | + $error_message = esc_html__( 'There was a problem uploading your file', 'elementor' ); | |
| 327 | 257 | |
| 328 | - $file = Utils::get_super_global_value( $_FILES, 'fileToUpload' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 329 | - | |
| 330 | 258 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 331 | - if ( ! is_array( $file ) || empty( $file['type'] ) ) { | |
| 259 | + if ( empty( $_FILES['fileToUpload'] ) || ! is_array( $_FILES['fileToUpload'] ) ) { | |
| 332 | 260 | return [ |
| 333 | 261 | 'status' => 'error', |
| 334 | 262 | 'payload' => [ |
| 335 | 263 | 'error_message' => $error_message, |
| @@ -338,9 +266,9 @@ | ||
| 338 | 266 | } |
| 339 | 267 | |
| 340 | 268 | // If the user has allowed it, set the Request's state as an "Elementor Upload" request, in order to add |
| 341 | 269 | // support for non-standard file uploads. |
| 342 | - if ( 'image/svg+xml' === $file['type'] ) { | |
| 270 | + if ( 'image/svg+xml' === $_FILES['fileToUpload']['type'] ) { | |
| 343 | 271 | if ( Uploads_Manager::are_unfiltered_uploads_enabled() ) { |
| 344 | 272 | Plugin::$instance->uploads_manager->set_elementor_upload_state( true ); |
| 345 | 273 | } else { |
| 346 | 274 | wp_send_json_error( 'To upload SVG files, you must allow uploading unfiltered files.' ); |
| @@ -347,11 +275,11 @@ | ||
| 347 | 275 | } |
| 348 | 276 | } |
| 349 | 277 | |
| 350 | 278 | // If the image is an SVG file, sanitation is performed during the import (upload) process. |
| 351 | - $image_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( $file ); | |
| 279 | + $image_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( $_FILES['fileToUpload'] ); | |
| 352 | 280 | |
| 353 | - if ( 'image/svg+xml' === $file['type'] && Uploads_Manager::are_unfiltered_uploads_enabled() ) { | |
| 281 | + if ( 'image/svg+xml' === $_FILES['fileToUpload']['type'] && Uploads_Manager::are_unfiltered_uploads_enabled() ) { | |
| 354 | 282 | // Reset Upload state. |
| 355 | 283 | Plugin::$instance->uploads_manager->set_elementor_upload_state( false ); |
| 356 | 284 | } |
| 357 | 285 | |
| @@ -385,12 +313,10 @@ | ||
| 385 | 313 | if ( ! current_user_can( 'switch_themes' ) ) { |
| 386 | 314 | return $this->get_permission_error_response(); |
| 387 | 315 | } |
| 388 | 316 | |
| 389 | - $theme_slug = 'hello-elementor'; | |
| 317 | + switch_theme( 'hello-elementor' ); | |
| 390 | 318 | |
| 391 | - switch_theme( $theme_slug ); | |
| 392 | - | |
| 393 | 319 | return [ |
| 394 | 320 | 'status' => 'success', |
| 395 | 321 | 'payload' => [ |
| 396 | 322 | 'helloThemeActivated' => true, |
| @@ -409,14 +335,12 @@ | ||
| 409 | 335 | if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) ) { |
| 410 | 336 | return $this->get_permission_error_response(); |
| 411 | 337 | } |
| 412 | 338 | |
| 413 | - $error_message = esc_html__( 'There was a problem uploading your file.', 'elementor' ); | |
| 339 | + $error_message = esc_html__( 'There was a problem uploading your file', 'elementor' ); | |
| 414 | 340 | |
| 415 | - $file = Utils::get_super_global_value( $_FILES, 'fileToUpload' ) ?? []; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 416 | - | |
| 417 | 341 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 418 | - if ( ! is_array( $file ) || empty( $file['type'] ) ) { | |
| 342 | + if ( empty( $_FILES['fileToUpload'] ) || ! is_array( $_FILES['fileToUpload'] ) ) { | |
| 419 | 343 | return [ |
| 420 | 344 | 'status' => 'error', |
| 421 | 345 | 'payload' => [ |
| 422 | 346 | 'error_message' => $error_message, |
| @@ -431,9 +355,9 @@ | ||
| 431 | 355 | } |
| 432 | 356 | |
| 433 | 357 | $skin = new Automatic_Upgrader_Skin(); |
| 434 | 358 | $upgrader = new Plugin_Upgrader( $skin ); |
| 435 | - $upload_result = $upgrader->install( $file['tmp_name'], [ 'overwrite_package' => false ] ); | |
| 359 | + $upload_result = $upgrader->install( $_FILES['fileToUpload']['tmp_name'], [ 'overwrite_package' => false ] ); | |
| 436 | 360 | |
| 437 | 361 | if ( ! $upload_result || is_wp_error( $upload_result ) ) { |
| 438 | 362 | $result = [ |
| 439 | 363 | 'status' => 'error', |
| @@ -481,18 +405,19 @@ | ||
| 481 | 405 | /** |
| 482 | 406 | * Maybe Handle Ajax |
| 483 | 407 | * |
| 484 | 408 | * This method checks if there are any AJAX actions being |
| 409 | + * @since 3.6.0 | |
| 485 | 410 | * |
| 486 | - * @since 3.6.0 | |
| 411 | + * @return array|null | |
| 487 | 412 | */ |
| 488 | 413 | private function maybe_handle_ajax() { |
| 489 | 414 | $result = []; |
| 490 | 415 | |
| 491 | 416 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 492 | - switch ( Utils::get_super_global_value( $_POST, 'action' ) ) { | |
| 417 | + switch ( $_POST['action'] ) { | |
| 493 | 418 | case 'elementor_update_site_name': |
| 494 | - // If no value is passed for any reason, no need to update the site name. | |
| 419 | + // If no value is passed for any reason, no need ot update the site name. | |
| 495 | 420 | $result = $this->maybe_update_site_name(); |
| 496 | 421 | break; |
| 497 | 422 | case 'elementor_update_site_logo': |
| 498 | 423 | $result = $this->maybe_update_site_logo(); |
| @@ -507,12 +432,8 @@ | ||
| 507 | 432 | $result = $this->upload_and_install_pro(); |
| 508 | 433 | break; |
| 509 | 434 | case 'elementor_update_onboarding_option': |
| 510 | 435 | $result = $this->maybe_update_onboarding_db_option(); |
| 511 | - break; | |
| 512 | - case 'elementor_save_onboarding_features': | |
| 513 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 514 | - $result = $this->get_component( 'features_usage' )->save_onboarding_features( Utils::get_super_global_value( $_POST, 'data' ) ?? [] ); | |
| 515 | 436 | } |
| 516 | 437 | |
| 517 | 438 | if ( ! empty( $result ) ) { |
| 518 | 439 | if ( 'success' === $result['status'] ) { |
| @@ -523,10 +444,8 @@ | ||
| 523 | 444 | } |
| 524 | 445 | } |
| 525 | 446 | |
| 526 | 447 | public function __construct() { |
| 527 | - $this->add_component( 'features_usage', new Features_Usage() ); | |
| 528 | - | |
| 529 | 448 | add_action( 'elementor/init', function() { |
| 530 | 449 | // Only load when viewing the onboarding app. |
| 531 | 450 | if ( Plugin::$instance->app->is_current() ) { |
| 532 | 451 | $this->set_onboarding_settings(); |
| @@ -533,19 +452,17 @@ | ||
| 533 | 452 | // Needed for installing the Hello Elementor theme. |
| 534 | 453 | wp_enqueue_script( 'updates' ); |
| 535 | 454 | // Needed for uploading Logo from WP Media Library. |
| 536 | 455 | wp_enqueue_media(); |
| 456 | + | |
| 457 | + Plugin::$instance->app->set_settings( 'disable_dark_theme', true ); | |
| 537 | 458 | } |
| 538 | 459 | }, 12 ); |
| 539 | 460 | |
| 540 | 461 | // Needed for uploading Logo from WP Media Library. The 'admin_menu' hook is used because it runs before |
| 541 | 462 | // 'admin_init', and the App triggers printing footer scripts on 'admin_init' at priority 0. |
| 542 | - add_action( 'admin_menu', function () { | |
| 543 | - add_action( 'wp_print_footer_scripts', function () { | |
| 544 | - if ( function_exists( 'wp_print_media_templates' ) ) { | |
| 545 | - wp_print_media_templates(); | |
| 546 | - } | |
| 547 | - } ); | |
| 463 | + add_action( 'admin_menu', function() { | |
| 464 | + add_action( 'wp_print_footer_scripts', 'wp_print_media_templates' ); | |
| 548 | 465 | } ); |
| 549 | 466 | |
| 550 | 467 | add_action( 'admin_init', function() { |
| 551 | 468 | if ( wp_doing_ajax() && |
| @@ -550,14 +467,12 @@ | ||
| 550 | 467 | add_action( 'admin_init', function() { |
| 551 | 468 | if ( wp_doing_ajax() && |
| 552 | 469 | isset( $_POST['action'] ) && |
| 553 | 470 | isset( $_POST['_nonce'] ) && |
| 554 | - wp_verify_nonce( Utils::get_super_global_value( $_POST, '_nonce' ), Ajax::NONCE_KEY ) && | |
| 471 | + wp_verify_nonce( $_POST['_nonce'], Ajax::NONCE_KEY ) && | |
| 555 | 472 | current_user_can( 'manage_options' ) |
| 556 | 473 | ) { |
| 557 | 474 | $this->maybe_handle_ajax(); |
| 558 | 475 | } |
| 559 | 476 | } ); |
| 560 | - | |
| 561 | - $this->get_component( 'features_usage' )->register(); | |
| 562 | 477 | } |
| 563 | 478 | } |