| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\App\Modules\Onboarding; |
| 4 | 4 | |
| 5 | 5 | use Elementor\App\Modules\Onboarding\Data\Controller; |
| 6 | +use Elementor\App\Modules\Onboarding\Data\Endpoints\Install_Theme; | |
| 6 | 7 | use Elementor\App\Modules\Onboarding\Storage\Entities\User_Choices; |
| 7 | 8 | use Elementor\App\Modules\Onboarding\Storage\Entities\User_Progress; |
| 8 | 9 | use Elementor\App\Modules\Onboarding\Storage\Onboarding_Progress_Manager; |
| 9 | 10 | use Elementor\Core\Base\Module as BaseModule; |
| @@ -50,8 +51,15 @@ | ||
| 50 | 51 | |
| 51 | 52 | Plugin::instance()->data_manager_v2->register_controller( new Controller() ); |
| 52 | 53 | |
| 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 | + } | |
| 54 | 62 | } |
| 55 | 63 | |
| 56 | 64 | public function on_elementor_init(): void { |
| 57 | 65 | if ( ! Plugin::instance()->app->is_current() ) { |
| @@ -70,8 +78,19 @@ | ||
| 70 | 78 | ELEMENTOR_VERSION |
| 71 | 79 | ); |
| 72 | 80 | } |
| 73 | 81 | |
| 82 | + public function enqueue_starter_preview_css(): void { | |
| 83 | + $css = ' | |
| 84 | + #site-header, | |
| 85 | + .page-header { display: var(--e-starter-header-display, none); } | |
| 86 | + '; | |
| 87 | + | |
| 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 | + } | |
| 92 | + | |
| 74 | 93 | public function progress_manager(): Onboarding_Progress_Manager { |
| 75 | 94 | return $this->progress_manager; |
| 76 | 95 | } |
| 77 | 96 | |
| @@ -102,9 +121,8 @@ | ||
| 102 | 121 | 'steps' => $steps, |
| 103 | 122 | 'uiTheme' => $this->get_ui_theme_preference(), |
| 104 | 123 | 'translations' => $this->get_translated_strings(), |
| 105 | 124 | 'shouldShowProInstallScreen' => $is_connected ? $this->should_show_pro_install_screen() : false, |
| 106 | - 'isHelloThemeActive' => $this->is_hello_theme_active(), | |
| 107 | 125 | 'urls' => [ |
| 108 | 126 | 'dashboard' => admin_url(), |
| 109 | 127 | 'editor' => admin_url( 'edit.php?post_type=elementor_library' ), |
| 110 | 128 | 'connect' => $this->get_connect_url(), |
| @@ -117,28 +135,21 @@ | ||
| 117 | 135 | } |
| 118 | 136 | |
| 119 | 137 | private function validate_progress_for_steps( User_Progress $progress, array $steps ): array { |
| 120 | 138 | $progress_data = $progress->to_array(); |
| 121 | - $step_ids = array_column( $steps, 'id' ); | |
| 122 | 139 | $step_count = count( $steps ); |
| 123 | - $fallback_step_id = $steps[0]['id'] ?? 'site_features'; | |
| 124 | 140 | $current_step_index = $progress->get_current_step_index() ?? 0; |
| 125 | - $current_step_id = $progress->get_current_step_id() ?? $fallback_step_id; | |
| 141 | + $current_step_id = $progress->get_current_step_id() ?? $steps[0]['id'] ?? 'building_for'; | |
| 126 | 142 | |
| 127 | 143 | $is_invalid_step_index = $current_step_index < 0 || $current_step_index >= $step_count; |
| 128 | - $is_invalid_step_id = ! in_array( $current_step_id, $step_ids, true ); | |
| 129 | 144 | |
| 130 | - if ( $is_invalid_step_index || $is_invalid_step_id ) { | |
| 131 | - $current_step_id = $fallback_step_id; | |
| 145 | + if ( $is_invalid_step_index ) { | |
| 146 | + $current_step_id = $steps[0]['id']; | |
| 132 | 147 | $current_step_index = 0; |
| 133 | 148 | } |
| 134 | 149 | |
| 135 | 150 | $progress_data['current_step_id'] = $current_step_id; |
| 136 | 151 | $progress_data['current_step_index'] = $current_step_index; |
| 137 | - $progress_data['completed_steps'] = array_values( array_filter( | |
| 138 | - $progress->get_completed_steps(), | |
| 139 | - static fn( $step_id ) => in_array( $step_id, $step_ids, true ) | |
| 140 | - ) ); | |
| 141 | 152 | |
| 142 | 153 | return $progress_data; |
| 143 | 154 | } |
| 144 | 155 | |
| @@ -175,9 +186,9 @@ | ||
| 175 | 186 | return $connect->get_app( 'library' ); |
| 176 | 187 | } |
| 177 | 188 | |
| 178 | 189 | public static function should_show_pro_install_screen(): bool { |
| 179 | - if ( Utils::has_pro() || Utils::is_pro_installed_and_not_active() ) { | |
| 190 | + if ( self::is_elementor_pro_installed() ) { | |
| 180 | 191 | return false; |
| 181 | 192 | } |
| 182 | 193 | |
| 183 | 194 | $connect = Plugin::$instance->common->get_component( 'connect' ); |
| @@ -216,8 +227,30 @@ | ||
| 216 | 227 | |
| 217 | 228 | return $user->first_name ?? ''; |
| 218 | 229 | } |
| 219 | 230 | |
| 231 | + public function should_show_starter(): bool { | |
| 232 | + $progress = $this->progress_manager->get_progress(); | |
| 233 | + | |
| 234 | + return self::VERSION === get_option( self::ONBOARDING_OPTION ) && ! $progress->is_starter_dismissed(); | |
| 235 | + } | |
| 236 | + | |
| 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', | |
| 248 | + ]; | |
| 249 | + | |
| 250 | + return $settings; | |
| 251 | + } | |
| 252 | + | |
| 220 | 253 | private function maybe_invalidate_theme_selection( User_Progress $progress, User_Choices $choices ): void { |
| 221 | 254 | $selected_theme = $choices->get_theme_selection(); |
| 222 | 255 | |
| 223 | 256 | if ( empty( $selected_theme ) ) { |
| @@ -278,13 +311,31 @@ | ||
| 278 | 311 | |
| 279 | 312 | private function get_steps_config(): array { |
| 280 | 313 | $steps = [ |
| 281 | 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 | + ]; | |
| 330 | + | |
| 331 | + if ( ! $this->is_elementor_theme_active() ) { | |
| 332 | + $steps[] = [ | |
| 282 | 333 | 'id' => 'theme_selection', |
| 283 | 334 | 'label' => __( 'Start with a theme that fits your needs', 'elementor' ), |
| 284 | 335 | 'type' => 'single', |
| 285 | - ], | |
| 286 | - ]; | |
| 336 | + ]; | |
| 337 | + } | |
| 287 | 338 | |
| 288 | 339 | if ( ! self::is_elementor_pro_installed() ) { |
| 289 | 340 | $steps[] = [ |
| 290 | 341 | 'id' => 'site_features', |
| @@ -296,17 +347,15 @@ | ||
| 296 | 347 | return apply_filters( 'elementor/onboarding/steps', $steps ); |
| 297 | 348 | } |
| 298 | 349 | |
| 299 | 350 | private static function is_elementor_pro_installed(): bool { |
| 300 | - $is_pro_installed = Utils::has_pro(); | |
| 351 | + $is_pro_installed = Utils::has_pro() || Utils::is_pro_installed_and_not_active(); | |
| 301 | 352 | return (bool) apply_filters( 'elementor/onboarding/is_elementor_pro_installed', $is_pro_installed ); |
| 302 | 353 | } |
| 303 | 354 | |
| 304 | - private function is_hello_theme_active(): bool { | |
| 355 | + private function is_elementor_theme_active(): bool { | |
| 305 | 356 | $active_theme = get_stylesheet(); |
| 306 | - $is_active = 0 === strpos( $active_theme, 'hello-' ); | |
| 307 | - | |
| 308 | - $is_active = (bool) apply_filters( 'elementor/onboarding/is_hello_theme_active', $is_active ); | |
| 357 | + $is_active = in_array( $active_theme, Install_Theme::ALLOWED_THEMES, true ); | |
| 309 | 358 | |
| 310 | 359 | return (bool) apply_filters( 'elementor/onboarding/is_elementor_theme_active', $is_active ); |
| 311 | 360 | } |
| 312 | 361 | } |