| @@ -5,15 +5,15 @@ | ||
| 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; |
| 10 | +use Elementor\Tracker; | |
| 11 | 11 | use Elementor\Utils; |
| 12 | 12 | use Plugin_Upgrader; |
| 13 | 13 | |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | - exit; // Exit if accessed directly. | |
| 15 | + exit; // Exit if accessed directly | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Onboarding Module |
| @@ -26,16 +26,8 @@ | ||
| 26 | 26 | |
| 27 | 27 | const VERSION = '1.0.0'; |
| 28 | 28 | const ONBOARDING_OPTION = 'elementor_onboarded'; |
| 29 | 29 | |
| 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 | 30 | /** |
| 39 | 31 | * Get name. |
| 40 | 32 | * |
| 41 | 33 | * @since 3.6.0 |
| @@ -46,44 +38,8 @@ | ||
| 46 | 38 | public function get_name() { |
| 47 | 39 | return 'onboarding'; |
| 48 | 40 | } |
| 49 | 41 | |
| 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 | 42 | /** |
| 87 | 43 | * Set Onboarding Settings |
| 88 | 44 | * |
| 89 | 45 | * Creates an array of module settings that is localized into the JS App config. |
| @@ -112,9 +68,8 @@ | ||
| 112 | 68 | $hello_theme_errors = is_object( $hello_theme->errors() ) ? $hello_theme->errors()->errors : []; |
| 113 | 69 | |
| 114 | 70 | /** @var Library $library */ |
| 115 | 71 | $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 | 72 | |
| 118 | 73 | Plugin::$instance->app->set_settings( 'onboarding', [ |
| 119 | 74 | 'eventPlacement' => 'Onboarding wizard', |
| 120 | 75 | 'onboardingAlreadyRan' => get_option( self::ONBOARDING_OPTION ), |
| @@ -121,23 +76,15 @@ | ||
| 121 | 76 | 'onboardingVersion' => self::VERSION, |
| 122 | 77 | 'isLibraryConnected' => $library->is_connected(), |
| 123 | 78 | // Used to check if the Hello Elementor theme is installed but not activated. |
| 124 | 79 | 'helloInstalled' => empty( $hello_theme_errors['theme_not_found'] ), |
| 125 | - 'helloActivated' => $this->is_hello_theme_activated(), | |
| 80 | + 'helloActivated' => 'hello-elementor' === get_option( 'template' ), | |
| 126 | 81 | // The "Use Hello theme on my site" checkbox should be checked by default only if this condition is met. |
| 127 | 82 | 'helloOptOut' => count( $pages_and_posts->posts ) < 5, |
| 128 | 83 | 'siteName' => esc_html( $site_name ), |
| 129 | 84 | 'isUnfilteredFilesEnabled' => Uploads_Manager::are_unfiltered_uploads_enabled(), |
| 130 | - 'isEditorOneActive' => $is_editor_one_active, | |
| 131 | 85 | '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' ), | |
| 86 | + 'kitLibrary' => Plugin::$instance->app->get_base_url() . '#/kit-library?order[direction]=desc&order[by]=featuredIndex', | |
| 140 | 87 | 'createNewPage' => Plugin::$instance->documents->get_create_new_post_url(), |
| 141 | 88 | 'connect' => $library->get_admin_url( 'authorize', [ |
| 142 | 89 | 'utm_source' => 'onboarding-wizard', |
| 143 | 90 | 'utm_campaign' => 'connect-account', |
| @@ -144,9 +91,8 @@ | ||
| 144 | 91 | 'utm_medium' => 'wp-dash', |
| 145 | 92 | 'utm_term' => self::VERSION, |
| 146 | 93 | 'source' => 'generic', |
| 147 | 94 | ] ), |
| 148 | - 'upgrade' => 'https://go.elementor.com/go-pro-onboarding-wizard-upgrade/', | |
| 149 | 95 | 'signUp' => $library->get_admin_url( 'authorize', [ |
| 150 | 96 | 'utm_source' => 'onboarding-wizard', |
| 151 | 97 | 'utm_campaign' => 'connect-account', |
| 152 | 98 | 'utm_medium' => 'wp-dash', |
| @@ -166,23 +112,8 @@ | ||
| 166 | 112 | 'connectCtaLink' => '&utm_content=cta-link', |
| 167 | 113 | 'downloadPro' => '?utm_source=onboarding-wizard&utm_campaign=my-account-subscriptions&utm_medium=wp-dash&utm_content=import-pro-plugin&utm_term=' . self::VERSION, |
| 168 | 114 | ], |
| 169 | 115 | '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 | 116 | ] ); |
| 186 | 117 | } |
| 187 | 118 | |
| 188 | 119 | /** |
| @@ -197,9 +128,9 @@ | ||
| 197 | 128 | private function get_permission_error_response() { |
| 198 | 129 | return [ |
| 199 | 130 | 'status' => 'error', |
| 200 | 131 | 'payload' => [ |
| 201 | - 'error_message' => esc_html__( 'You do not have permission to perform this action.', 'elementor' ), | |
| 132 | + 'error_message' => esc_html__( 'You do not have permissions to perform this action.', 'elementor' ), | |
| 202 | 133 | ], |
| 203 | 134 | ]; |
| 204 | 135 | } |
| 205 | 136 | |
| @@ -324,9 +255,9 @@ | ||
| 324 | 255 | */ |
| 325 | 256 | private function maybe_upload_logo_image() { |
| 326 | 257 | $error_message = esc_html__( 'There was a problem uploading your file.', 'elementor' ); |
| 327 | 258 | |
| 328 | - $file = Utils::get_super_global_value( $_FILES, 'fileToUpload' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 259 | + $file = Utils::get_super_global_value( $_FILES, 'fileToUpload' ); | |
| 329 | 260 | |
| 330 | 261 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 331 | 262 | if ( ! is_array( $file ) || empty( $file['type'] ) ) { |
| 332 | 263 | return [ |
| @@ -385,12 +316,10 @@ | ||
| 385 | 316 | if ( ! current_user_can( 'switch_themes' ) ) { |
| 386 | 317 | return $this->get_permission_error_response(); |
| 387 | 318 | } |
| 388 | 319 | |
| 389 | - $theme_slug = 'hello-elementor'; | |
| 320 | + switch_theme( 'hello-elementor' ); | |
| 390 | 321 | |
| 391 | - switch_theme( $theme_slug ); | |
| 392 | - | |
| 393 | 322 | return [ |
| 394 | 323 | 'status' => 'success', |
| 395 | 324 | 'payload' => [ |
| 396 | 325 | 'helloThemeActivated' => true, |
| @@ -411,9 +340,9 @@ | ||
| 411 | 340 | } |
| 412 | 341 | |
| 413 | 342 | $error_message = esc_html__( 'There was a problem uploading your file.', 'elementor' ); |
| 414 | 343 | |
| 415 | - $file = Utils::get_super_global_value( $_FILES, 'fileToUpload' ) ?? []; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 344 | + $file = Utils::get_super_global_value( $_FILES, 'fileToUpload' ) ?? []; | |
| 416 | 345 | |
| 417 | 346 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 418 | 347 | if ( ! is_array( $file ) || empty( $file['type'] ) ) { |
| 419 | 348 | return [ |
| @@ -481,10 +410,11 @@ | ||
| 481 | 410 | /** |
| 482 | 411 | * Maybe Handle Ajax |
| 483 | 412 | * |
| 484 | 413 | * This method checks if there are any AJAX actions being |
| 414 | + * @since 3.6.0 | |
| 485 | 415 | * |
| 486 | - * @since 3.6.0 | |
| 416 | + * @return array|null | |
| 487 | 417 | */ |
| 488 | 418 | private function maybe_handle_ajax() { |
| 489 | 419 | $result = []; |
| 490 | 420 | |
| @@ -490,9 +420,9 @@ | ||
| 490 | 420 | |
| 491 | 421 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 492 | 422 | switch ( Utils::get_super_global_value( $_POST, 'action' ) ) { |
| 493 | 423 | case 'elementor_update_site_name': |
| 494 | - // If no value is passed for any reason, no need to update the site name. | |
| 424 | + // If no value is passed for any reason, no need ot update the site name. | |
| 495 | 425 | $result = $this->maybe_update_site_name(); |
| 496 | 426 | break; |
| 497 | 427 | case 'elementor_update_site_logo': |
| 498 | 428 | $result = $this->maybe_update_site_logo(); |
| @@ -507,12 +437,8 @@ | ||
| 507 | 437 | $result = $this->upload_and_install_pro(); |
| 508 | 438 | break; |
| 509 | 439 | case 'elementor_update_onboarding_option': |
| 510 | 440 | $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 | 441 | } |
| 516 | 442 | |
| 517 | 443 | if ( ! empty( $result ) ) { |
| 518 | 444 | if ( 'success' === $result['status'] ) { |
| @@ -523,10 +449,8 @@ | ||
| 523 | 449 | } |
| 524 | 450 | } |
| 525 | 451 | |
| 526 | 452 | public function __construct() { |
| 527 | - $this->add_component( 'features_usage', new Features_Usage() ); | |
| 528 | - | |
| 529 | 453 | add_action( 'elementor/init', function() { |
| 530 | 454 | // Only load when viewing the onboarding app. |
| 531 | 455 | if ( Plugin::$instance->app->is_current() ) { |
| 532 | 456 | $this->set_onboarding_settings(); |
| @@ -556,8 +480,6 @@ | ||
| 556 | 480 | ) { |
| 557 | 481 | $this->maybe_handle_ajax(); |
| 558 | 482 | } |
| 559 | 483 | } ); |
| 560 | - | |
| 561 | - $this->get_component( 'features_usage' )->register(); | |
| 562 | 484 | } |
| 563 | 485 | } |