| @@ -61,13 +61,45 @@ | ||
| 61 | 61 | public function init(): void { |
| 62 | 62 | |
| 63 | 63 | add_action( $this->prefix.'_onboarding_update_options', array($this, 'update_step_settings'), 10, 2 ); |
| 64 | 64 | add_filter( $this->prefix.'_onboarding_steps', array($this, 'load_steps')); |
| 65 | + add_action( 'admin_post_wpo_reopen_onboarding', array($this, 'handle_reopen_onboarding') ); | |
| 65 | 66 | |
| 66 | 67 | $this->setup_onboarding(); |
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | /** |
| 71 | + * Handles the "Quick Setup" button: re-activates the onboarding wizard and redirects to the dashboard. | |
| 72 | + * | |
| 73 | + * @return void | |
| 74 | + */ | |
| 75 | + public function handle_reopen_onboarding(): void { | |
| 76 | + check_admin_referer('wpo_reopen_onboarding'); | |
| 77 | + | |
| 78 | + $capability = $this->is_multisite ? 'manage_network_options' : 'manage_options'; | |
| 79 | + if (!current_user_can($capability)) { | |
| 80 | + wp_die(esc_html__('Sorry, you are not allowed to do this.', 'wp-optimize')); | |
| 81 | + } | |
| 82 | + | |
| 83 | + $this->activate_onboarding_wizard(); | |
| 84 | + | |
| 85 | + wp_safe_redirect(WP_Optimize()->get_options()->admin_page_url('WP-Optimize')); | |
| 86 | + exit; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Returns the URL that reopens the onboarding wizard, including a nonce. | |
| 91 | + * | |
| 92 | + * @return string | |
| 93 | + */ | |
| 94 | + public function get_reopen_onboarding_url(): string { | |
| 95 | + return wp_nonce_url( | |
| 96 | + admin_url('admin-post.php?action=wpo_reopen_onboarding'), | |
| 97 | + 'wpo_reopen_onboarding' | |
| 98 | + ); | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 70 | 102 | * Get Features Status |
| 71 | 103 | * |
| 72 | 104 | * @param array $settings Settings data |
| 73 | 105 | * @param array $step_fields Step Fields data |
| @@ -92,51 +124,137 @@ | ||
| 92 | 124 | |
| 93 | 125 | $id = (string) $setting['id']; |
| 94 | 126 | $value = isset($setting['value']) ? (bool) $setting['value'] : false; |
| 95 | 127 | |
| 96 | - if ('enable_caching_onboarding' === $id) { | |
| 97 | - $wpo_page_cache = WP_Optimize()->get_page_cache(); | |
| 128 | + $this->apply_setting($id, $value); | |
| 129 | + } | |
| 130 | + } | |
| 98 | 131 | |
| 99 | - if (true === $value) { | |
| 100 | - $wpo_page_cache->enable(true); | |
| 101 | - } else { | |
| 102 | - $wpo_page_cache->disable(); | |
| 103 | - } | |
| 104 | - } | |
| 132 | + /** | |
| 133 | + * Dispatch a setting change to its handler. | |
| 134 | + * | |
| 135 | + * @param string $id Setting identifier. | |
| 136 | + * @param bool $value Whether to enable or disable the setting. | |
| 137 | + * @return void | |
| 138 | + */ | |
| 139 | + private function apply_setting(string $id, bool $value): void { | |
| 140 | + $handlers = array( | |
| 141 | + 'enable_caching_onboarding' => array($this, 'apply_caching_setting'), | |
| 142 | + 'enable_minify_onboarding' => array($this, 'apply_minify_setting'), | |
| 143 | + 'enable_image_optimization_onboarding' => array($this, 'apply_image_setting'), | |
| 144 | + ); | |
| 105 | 145 | |
| 106 | - if ('enable_minify_onboarding' === $id) { | |
| 107 | - wp_optimize_minify_config()->update(array('enabled' => $value)); | |
| 108 | - } | |
| 146 | + if (isset($handlers[$id])) { | |
| 147 | + call_user_func($handlers[$id], $value); | |
| 148 | + } | |
| 149 | + } | |
| 109 | 150 | |
| 110 | - if ('enable_image_compression_onboarding' === $id) { | |
| 111 | - Updraft_Smush_Manager()->update_smush_options(array('autosmush' => $value)); | |
| 112 | - } | |
| 151 | + /** | |
| 152 | + * Enable or disable page caching. | |
| 153 | + * | |
| 154 | + * Some related handling is intentionally commented out pending further work. | |
| 155 | + * | |
| 156 | + * @param bool $value True to enable, false to disable. | |
| 157 | + * @return void | |
| 158 | + */ | |
| 159 | + private function apply_caching_setting(bool $value): void { | |
| 160 | + $page_cache = WP_Optimize()->get_page_cache(); | |
| 113 | 161 | |
| 114 | - if ('enable_webp_conversion_onboarding' === $id) { | |
| 115 | - $webp_data = array(); | |
| 116 | - $webp_data['webp_conversion'] = $value; | |
| 117 | - WP_Optimize()->get_webp_instance()->save_webp_settings($webp_data); | |
| 118 | - } | |
| 162 | + if ($value) { | |
| 163 | + $page_cache->enable(true); | |
| 164 | + // $this->enable_gzip(); | |
| 165 | + // $this->enable_browser_cache(); | |
| 166 | + } else { | |
| 167 | + $page_cache->disable(); | |
| 168 | + // WP_Optimize()->get_gzip_compression()->disable(); | |
| 169 | + // WP_Optimize()->get_browser_cache()->disable(); | |
| 170 | + } | |
| 119 | 171 | |
| 120 | - if ('enable_lazy_load_onboarding' === $id) { | |
| 121 | - $lazy_settings = array(); | |
| 122 | - $lazy_settings['lazyload'] = array( | |
| 123 | - 'images' => $value, | |
| 124 | - 'iframes' => $value, | |
| 125 | - 'backgrounds' => $value, | |
| 126 | - 'youtube_preview' => $value, | |
| 127 | - 'skip_classes' => '', | |
| 128 | - ); | |
| 129 | - WP_Optimize()->get_options()->save_lazy_load_settings($lazy_settings); | |
| 130 | - } | |
| 172 | + if ($this->is_premium) { | |
| 173 | + // $this->set_show_avatars($value); | |
| 174 | + WP_Optimize_LCP_Settings::instance()->update_setting($value); | |
| 175 | + } | |
| 176 | + } | |
| 131 | 177 | |
| 132 | - if ('enable_image_dimensions_onboarding' === $id) { | |
| 133 | - WP_Optimize()->get_options()->update_option('image_dimensions', (int) $value); | |
| 134 | - } | |
| 178 | + /** | |
| 179 | + * Enable gzip compression. | |
| 180 | + * | |
| 181 | + * @return void | |
| 182 | + */ | |
| 183 | + private function enable_gzip(): void { | |
| 184 | + WP_Optimize()->get_gzip_compression()->enable_gzip_command_handler(array('enable' => true)); | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 188 | + * Enable browser cache using saved expiry options. | |
| 189 | + * | |
| 190 | + * @return void | |
| 191 | + */ | |
| 192 | + private function enable_browser_cache(): void { | |
| 193 | + $options = WP_Optimize()->get_options(); | |
| 194 | + WP_Optimize()->get_browser_cache()->enable_browser_cache_command_handler(array( | |
| 195 | + 'browser_cache_expire_days' => $options->get_option('browser_cache_expire_days', '28'), | |
| 196 | + 'browser_cache_expire_hours' => $options->get_option('browser_cache_expire_hours', '0'), | |
| 197 | + )); | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * Enable or disable avatar display (premium only). | |
| 202 | + * | |
| 203 | + * @param bool $value True to show avatars, false to hide. | |
| 204 | + * @return void | |
| 205 | + */ | |
| 206 | + private function set_show_avatars(bool $value): void { | |
| 207 | + $commands = new WP_Optimize_Cache_Commands_Premium(); | |
| 208 | + if (is_callable(array($commands, 'change_show_avatars'))) { | |
| 209 | + $commands->change_show_avatars(array('show_avatars' => $value)); | |
| 135 | 210 | } |
| 136 | 211 | } |
| 137 | 212 | |
| 138 | 213 | /** |
| 214 | + * Enable or disable CSS/JS minification. | |
| 215 | + * | |
| 216 | + * @param bool $value True to enable, false to disable. | |
| 217 | + * @return void | |
| 218 | + */ | |
| 219 | + private function apply_minify_setting(bool $value): void { | |
| 220 | + $params = array('enabled' => $value); | |
| 221 | + | |
| 222 | + if ($this->is_premium) { | |
| 223 | + $params['enable_capo_js'] = $value; | |
| 224 | + $params['host_local_google_fonts'] = $value; | |
| 225 | + } | |
| 226 | + | |
| 227 | + wp_optimize_minify_config()->update($params); | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 231 | + * Enable or disable image optimization and related premium features like lazy load and image dimensions. | |
| 232 | + * | |
| 233 | + * @param bool $value True to enable, false to disable. | |
| 234 | + * @return void | |
| 235 | + */ | |
| 236 | + private function apply_image_setting(bool $value): void { | |
| 237 | + Updraft_Smush_Manager()->update_smush_options(array('autosmush' => $value)); | |
| 238 | + | |
| 239 | + WP_Optimize()->get_webp_instance()->save_webp_settings(array('webp_conversion' => $value)); | |
| 240 | + | |
| 241 | + if (!$this->is_premium) return; | |
| 242 | + | |
| 243 | + WP_Optimize()->get_options()->save_lazy_load_settings(array( | |
| 244 | + 'lazyload' => array( | |
| 245 | + 'images' => $value, | |
| 246 | + 'iframes' => $value, | |
| 247 | + 'backgrounds' => $value, | |
| 248 | + 'youtube_preview' => $value, | |
| 249 | + 'skip_classes' => '', | |
| 250 | + ), | |
| 251 | + )); | |
| 252 | + | |
| 253 | + WP_Optimize()->get_options()->update_option('image_dimensions', (int) $value); | |
| 254 | + } | |
| 255 | + | |
| 256 | + /** | |
| 139 | 257 | * Load the steps for the onboarding process. |
| 140 | 258 | * |
| 141 | 259 | * Builds and returns the steps depending on the user's |
| 142 | 260 | * premium status and license connection. |
| @@ -148,10 +266,10 @@ | ||
| 148 | 266 | public function load_steps($steps = array()): array { |
| 149 | 267 | // Build steps |
| 150 | 268 | $steps = array(); // To override all previous steps. |
| 151 | 269 | |
| 152 | - // Step 1: Intro | |
| 153 | - $steps[] = $this->intro_step(); | |
| 270 | + // Step 1: Feature settings | |
| 271 | + $steps[] = $this->features_step(); | |
| 154 | 272 | |
| 155 | 273 | // Step 2: License step (only for premium users without a connected license) |
| 156 | 274 | if ($this->should_add_license_step()) { |
| 157 | 275 | $steps[] = $this->license_step(); |
| @@ -156,23 +274,20 @@ | ||
| 156 | 274 | if ($this->should_add_license_step()) { |
| 157 | 275 | $steps[] = $this->license_step(); |
| 158 | 276 | } |
| 159 | 277 | |
| 160 | - // Step 3: Feature settings | |
| 161 | - $steps[] = $this->features_step(); | |
| 162 | - | |
| 163 | - // Step 4: Newsletter signup | |
| 278 | + // Step 3: Newsletter signup | |
| 164 | 279 | $steps[] = $this->newsletter_step(); |
| 165 | 280 | |
| 166 | - // Step 5: Recommended plugins | |
| 281 | + // Step 4: Recommended plugins | |
| 167 | 282 | $steps[] = $this->plugins_install_step(); |
| 168 | 283 | |
| 169 | - // Step 6: Go Premium step (only for non-premium users) | |
| 284 | + // Step 5: Go Premium step (only for non-premium users) | |
| 170 | 285 | if (!$this->is_premium) { |
| 171 | 286 | $steps[] = $this->go_premium_step(); |
| 172 | 287 | } |
| 173 | 288 | |
| 174 | - // Step 7: Final step | |
| 289 | + // Step 6: Final step | |
| 175 | 290 | $steps[] = $this->last_step(); |
| 176 | 291 | |
| 177 | 292 | return $steps; |
| 178 | 293 | } |
| @@ -186,38 +301,8 @@ | ||
| 186 | 301 | return $this->is_premium && !$this->is_license_connected(); |
| 187 | 302 | } |
| 188 | 303 | |
| 189 | 304 | /** |
| 190 | - * Build the intro step for the onboarding wizard. | |
| 191 | - * | |
| 192 | - * This step introduces the plugin to the user, displays key | |
| 193 | - * benefits as bullet points, and includes a start button. | |
| 194 | - * | |
| 195 | - * @return array Step configuration including ID, type, title, subtitle, intro bullets, button info, and note. | |
| 196 | - */ | |
| 197 | - private function intro_step(): array { | |
| 198 | - $intro_bullets = $this->get_intro_bullets(); | |
| 199 | - | |
| 200 | - $note_1 = $this->is_premium ? __("Premium plugin", 'wp-optimize') : __("Free plugin", 'wp-optimize'); | |
| 201 | - $note_2 = __("Quick setup", 'wp-optimize'); | |
| 202 | - $note_3 = __("No tech skills needed", 'wp-optimize'); | |
| 203 | - $bottom_note = $note_1 . ' • ' . $note_2 . ' • ' . $note_3; | |
| 204 | - return array( | |
| 205 | - 'id' => 'intro', | |
| 206 | - 'type' => 'intro', | |
| 207 | - 'title' => __('Let\'s get started!', 'wp-optimize'), | |
| 208 | - 'subtitle' => __("Speed up and optimize your WordPress site with ease, trusted by over 1 million sites.", 'wp-optimize'), | |
| 209 | - 'intro_bullets' => $intro_bullets, | |
| 210 | - 'button' => array( | |
| 211 | - 'id' => 'start', | |
| 212 | - 'label' => __('Start', 'wp-optimize'), | |
| 213 | - 'icon' => 'magic-wand', | |
| 214 | - ), | |
| 215 | - 'note' => $bottom_note, | |
| 216 | - ); | |
| 217 | - } | |
| 218 | - | |
| 219 | - /** | |
| 220 | 305 | * Build the license activation step for the onboarding wizard. |
| 221 | 306 | * |
| 222 | 307 | * This step includes fields for email and password, conditional |
| 223 | 308 | * titles/subtitles based on license status, and a button to |
| @@ -255,9 +340,10 @@ | ||
| 255 | 340 | 'button' => array( |
| 256 | 341 | 'id' => 'activate', |
| 257 | 342 | 'label'=> __('Confirm and activate', 'wp-optimize'), |
| 258 | 343 | 'icon' => 'EastRoundedIcon', |
| 259 | - ) | |
| 344 | + ), | |
| 345 | + 'skip_step' => true | |
| 260 | 346 | ); |
| 261 | 347 | } |
| 262 | 348 | |
| 263 | 349 | /** |
| @@ -269,11 +355,10 @@ | ||
| 269 | 355 | $features = $this->get_feature_settings(); |
| 270 | 356 | return array( |
| 271 | 357 | 'id' => 'page_features', |
| 272 | 358 | 'type' => 'settings', |
| 273 | - 'icon' => 'settings', | |
| 274 | - 'title' => __('Enable best-practice settings', 'wp-optimize'), | |
| 275 | - 'subtitle' => __('We\'ve pre-selected core settings to speed up and optimize your site.', 'wp-optimize').' '.__('You can tweak them anytime.', 'wp-optimize'), | |
| 359 | + 'title' => __('Your site is already faster!', 'wp-optimize'), | |
| 360 | + 'subtitle' => __('We enabled these settings optimised for your site.', 'wp-optimize').' '.__('Turn off anything you don\'t need.', 'wp-optimize'), | |
| 276 | 361 | 'fields' => $features, |
| 277 | 362 | 'button' => array( |
| 278 | 363 | 'id' => 'save', |
| 279 | 364 | 'label'=> __('Save and continue', 'wp-optimize'), |
| @@ -279,13 +364,13 @@ | ||
| 279 | 364 | 'label'=> __('Save and continue', 'wp-optimize'), |
| 280 | 365 | 'icon' => 'EastRoundedIcon', |
| 281 | 366 | ), |
| 282 | 367 | 'skip_step' => array( |
| 283 | - 'icon' => 'info', | |
| 368 | + 'icon' => 'info', | |
| 284 | 369 | 'tooltip' => array( |
| 285 | 370 | 'text' => __('All above features will be disabled if you skip.', 'wp-optimize'), |
| 286 | 371 | ), |
| 287 | - ) | |
| 372 | + ), | |
| 288 | 373 | ); |
| 289 | 374 | } |
| 290 | 375 | |
| 291 | 376 | /** |
| @@ -306,8 +391,9 @@ | ||
| 306 | 391 | 'id' => 'save', |
| 307 | 392 | 'label'=> __('Save and continue', 'wp-optimize'), |
| 308 | 393 | 'icon' => 'EastRoundedIcon', |
| 309 | 394 | ), |
| 395 | + 'skip_step' => true | |
| 310 | 396 | ); |
| 311 | 397 | } |
| 312 | 398 | |
| 313 | 399 | /** |
| @@ -339,8 +425,9 @@ | ||
| 339 | 425 | 'id' => 'save', |
| 340 | 426 | 'label' => __('Install and continue', 'wp-optimize'), |
| 341 | 427 | 'icon' => 'EastRoundedIcon', |
| 342 | 428 | ), |
| 429 | + 'skip_step' => true | |
| 343 | 430 | ); |
| 344 | 431 | } |
| 345 | 432 | |
| 346 | 433 | /** |
| @@ -358,8 +445,9 @@ | ||
| 358 | 445 | 'subtitle' => __('The complete optimization suite with safe defaults and expert help.', 'wp-optimize'), |
| 359 | 446 | 'bullets' => $go_premium_step_bullets, |
| 360 | 447 | 'enable_premium_btn' => true, |
| 361 | 448 | 'premium_btn_text' => __('Upgrade to Premium', 'wp-optimize'), |
| 449 | + 'skip_step' => true | |
| 362 | 450 | ); |
| 363 | 451 | } |
| 364 | 452 | |
| 365 | 453 | /** |
| @@ -441,11 +529,11 @@ | ||
| 441 | 529 | * @return array Array containing two strings: [standard_subtitle, installing_subtitle]. |
| 442 | 530 | */ |
| 443 | 531 | private function get_last_step_subtitles(): array { |
| 444 | 532 | |
| 445 | - $subtitle = __('WP-Optimize is ready to help your site run faster.', 'wp-optimize'); | |
| 533 | + $subtitle = __('WP-Optimize is running.', 'wp-optimize'); | |
| 446 | 534 | $subtitle .= ' '; |
| 447 | - $subtitle .= __('You can review or customize settings whenever you like.', 'wp-optimize'); | |
| 535 | + $subtitle .= __('You can review and adjust any settings anytime from the settings page.', 'wp-optimize'); | |
| 448 | 536 | |
| 449 | 537 | $installing = __('Setting things up in the background...', 'wp-optimize') . '<br>'; |
| 450 | 538 | $installing .= __('This will only take a moment.', 'wp-optimize'); |
| 451 | 539 | |
| @@ -475,9 +563,9 @@ | ||
| 475 | 563 | __('Preload key requests', 'wp-optimize'), |
| 476 | 564 | ), |
| 477 | 565 | array( |
| 478 | 566 | __('User and role-based cache', 'wp-optimize'), |
| 479 | - __('Premium support and more', 'wp-optimize'), | |
| 567 | + __('Premium support and more', 'wp-optimize'), | |
| 480 | 568 | ), |
| 481 | 569 | ); |
| 482 | 570 | } |
| 483 | 571 | |
| @@ -511,152 +599,108 @@ | ||
| 511 | 599 | /** |
| 512 | 600 | * Get the list of feature settings for the onboarding wizard. |
| 513 | 601 | * |
| 514 | 602 | * Generates an array of feature configuration options, including |
| 515 | - * labels, types, defaults, and premium-locked items. | |
| 603 | + * labels, types, defaults, and details. | |
| 516 | 604 | * |
| 517 | 605 | * @return array List of feature setting definitions. |
| 518 | 606 | */ |
| 519 | 607 | private function get_feature_settings(): array { |
| 520 | - $premium_heading = ''; | |
| 521 | - $premium_text = ''; | |
| 522 | - $is_lock = !$this->is_premium; | |
| 523 | - if ($is_lock) { | |
| 524 | - list($premium_heading, $premium_text) = $this->get_premium_tooltip(); | |
| 525 | - } | |
| 608 | + $label_details = __('Details', 'wp-optimize'); | |
| 526 | 609 | |
| 527 | - $webp_instance = WP_Optimize()->get_webp_instance(); | |
| 528 | - $webp_tooltip = __('Serve modern WebP images for smaller downloads.', 'wp-optimize'); | |
| 529 | - $is_lock_webp = false; | |
| 610 | + $default_config = array( | |
| 611 | + 'type' => 'checkbox', | |
| 612 | + 'subtype' => 'switch', | |
| 613 | + 'layout' => 'card', | |
| 614 | + 'show_details_label' => $label_details, | |
| 615 | + 'hide_details_label' => $label_details, | |
| 616 | + 'default' => true, | |
| 617 | + ); | |
| 530 | 618 | |
| 531 | - $webp_result = $webp_instance->evaluate_webp_capability(); | |
| 532 | - if (!$webp_result['is_available']) { | |
| 533 | - $is_lock_webp = true; | |
| 534 | - $webp_tooltip = $webp_result['message']; | |
| 619 | + return array( | |
| 620 | + array_merge($default_config, $this->get_cache_feature()), | |
| 621 | + array_merge($default_config, $this->get_minify_feature()), | |
| 622 | + array_merge($default_config, $this->get_image_feature()), | |
| 623 | + ); | |
| 624 | + } | |
| 625 | + | |
| 626 | + /** | |
| 627 | + * Build the cache feature definition for the onboarding wizard. | |
| 628 | + * | |
| 629 | + * Covers page caching. | |
| 630 | + * For premium users, it also includes the Auto LCP preload description. | |
| 631 | + * | |
| 632 | + * @return array Feature field definition array. | |
| 633 | + */ | |
| 634 | + private function get_cache_feature(): array { | |
| 635 | + $details = __('Enables page caching.', 'wp-optimize'); | |
| 636 | + | |
| 637 | + if ($this->is_premium) { | |
| 638 | + $details .= ' '.__('Automatically improves Largest Contentful Paint (LCP) when supported.', 'wp-optimize'); | |
| 535 | 639 | } |
| 536 | 640 | |
| 641 | + $details .= ' '.__('You can turn these off individually anytime.', 'wp-optimize'); | |
| 537 | 642 | return array( |
| 538 | - array( | |
| 539 | - 'id' => 'enable_caching_onboarding', | |
| 540 | - 'key' => 'enable_caching_onboarding', | |
| 541 | - 'type' => 'checkbox', | |
| 542 | - 'subtype' => 'switch', | |
| 543 | - 'label' => __('Page caching', 'wp-optimize'), | |
| 544 | - 'tooltip' => array( | |
| 545 | - 'text' => __('Cache full pages for faster repeat visits.', 'wp-optimize'), | |
| 546 | - ), | |
| 547 | - 'default' => true, | |
| 548 | - ), | |
| 549 | - array( | |
| 550 | - 'id' => 'enable_minify_onboarding', | |
| 551 | - 'key' => 'enable_minify_onboarding', | |
| 552 | - 'type' => 'checkbox', | |
| 553 | - 'subtype' => 'switch', | |
| 554 | - 'label' => __('Minify static assets', 'wp-optimize'), | |
| 555 | - 'tooltip' => array( | |
| 556 | - 'text' => __('Shrink HTML, CSS and JavaScript files for quicker loads.', 'wp-optimize'), | |
| 557 | - ), | |
| 558 | - 'default' => true, | |
| 559 | - ), | |
| 560 | - array( | |
| 561 | - 'id' => 'enable_image_compression_onboarding', | |
| 562 | - 'key' => 'enable_image_compression_onboarding', | |
| 563 | - 'type' => 'checkbox', | |
| 564 | - 'subtype' => 'switch', | |
| 565 | - 'label' => __('Image compression', 'wp-optimize'), | |
| 566 | - 'tooltip' => array( | |
| 567 | - 'text' => __('Automatically reduce image file sizes on upload to improve page load speed.', 'wp-optimize').' '.__('In settings, you can adjust compression quality as well as manually compress existing images.', 'wp-optimize'), | |
| 568 | - ), | |
| 569 | - 'default' => true, | |
| 570 | - ), | |
| 571 | - array( | |
| 572 | - 'id' => 'enable_webp_conversion_onboarding', | |
| 573 | - 'key' => 'enable_webp_conversion_onboarding', | |
| 574 | - 'type' => 'checkbox', | |
| 575 | - 'subtype' => 'switch', | |
| 576 | - 'is_lock' => $is_lock_webp, | |
| 577 | - 'label' => __('WebP conversion', 'wp-optimize'), | |
| 578 | - 'tooltip' => array( | |
| 579 | - 'text' => $webp_tooltip, | |
| 580 | - ), | |
| 581 | - 'default' => !$is_lock_webp, | |
| 582 | - ), | |
| 583 | - array( | |
| 584 | - 'id' => 'enable_lazy_load_onboarding', | |
| 585 | - 'key' => 'enable_lazy_load_onboarding', | |
| 586 | - 'type' => 'checkbox', | |
| 587 | - 'subtype' => 'switch', | |
| 588 | - 'is_lock' => $is_lock, | |
| 589 | - 'label' => __('Lazy Loading', 'wp-optimize'), | |
| 590 | - 'tooltip' => array( | |
| 591 | - 'heading' => array( | |
| 592 | - 'text' => $is_lock ? $premium_heading : '' | |
| 593 | - ), | |
| 594 | - 'text' => $is_lock ? $premium_text : __('Load images and videos only when they enter the viewport.', 'wp-optimize'), | |
| 595 | - ), | |
| 596 | - 'default' => !$is_lock, | |
| 597 | - ), | |
| 598 | - array( | |
| 599 | - 'id' => 'enable_image_dimensions_onboarding', | |
| 600 | - 'key' => 'enable_image_dimensions_onboarding', | |
| 601 | - 'type' => 'checkbox', | |
| 602 | - 'subtype' => 'switch', | |
| 603 | - 'is_lock' => $is_lock, | |
| 604 | - 'label' => __('Image Dimensions', 'wp-optimize'), | |
| 605 | - 'tooltip' => array( | |
| 606 | - 'heading' => array( | |
| 607 | - 'text' => $is_lock ? $premium_heading : '' | |
| 608 | - ), | |
| 609 | - 'text' => $is_lock ? $premium_text : __('Auto-add missing width and height to improve load speed and reduce layout shifts.', 'wp-optimize'), | |
| 610 | - ), | |
| 611 | - 'default' => !$is_lock, | |
| 612 | - ), | |
| 643 | + 'id' => 'enable_caching_onboarding', | |
| 644 | + 'key' => 'enable_caching_onboarding', | |
| 645 | + 'label' => __('Faster pages', 'wp-optimize'), | |
| 646 | + 'icon' => 'speed', | |
| 647 | + 'summary' => __('Pages refresh in the background, so return visits are always fast.', 'wp-optimize'), | |
| 648 | + 'details' => $details, | |
| 613 | 649 | ); |
| 614 | 650 | } |
| 615 | 651 | |
| 616 | 652 | /** |
| 617 | - * Get the tooltip heading and text for premium-only features. | |
| 653 | + * Build the minification feature definition for the onboarding wizard. | |
| 618 | 654 | * |
| 619 | - * @return array An array with two values: heading and tooltip text. | |
| 655 | + * Covers CSS and JS minification and file bundling. | |
| 656 | + * For premium users, it also includes Capo.js and local Google Fonts hosting. | |
| 657 | + * | |
| 658 | + * @return array Feature field definition array. | |
| 620 | 659 | */ |
| 621 | - private function get_premium_tooltip(): array { | |
| 622 | - $heading = __('Premium feature ⚡', 'wp-optimize'); | |
| 660 | + private function get_minify_feature(): array { | |
| 661 | + $details = __('Minifies CSS and JavaScript, and bundles related files together.', 'wp-optimize'); | |
| 662 | + $details .= ' '.__('Payment provider scripts are excluded automatically.', 'wp-optimize'); | |
| 623 | 663 | |
| 624 | - $upgrade_url_tooltip = WP_Optimize_Utils::add_utm_params($this->upgrade_url, $this->get_utm_params_to_override('upgrade-to-premium', 'tooltip'), true); | |
| 625 | - $text = sprintf( | |
| 626 | - // translators: %s: Text with Link | |
| 627 | - __('%s to unlock this and other advanced options.', 'wp-optimize'), '<a href="'.esc_url($upgrade_url_tooltip).'" class="underline" target="_blank">' . __('Upgrade to Premium', 'wp-optimize') . '</a>'); | |
| 664 | + if ($this->is_premium) { | |
| 665 | + $details .= ' '.__('Includes Capo.js for smarter script loading and hosts Google Fonts locally to reduce external requests.', 'wp-optimize'); | |
| 666 | + } | |
| 628 | 667 | |
| 629 | - return array($heading, $text); | |
| 668 | + return array( | |
| 669 | + 'id' => 'enable_minify_onboarding', | |
| 670 | + 'key' => 'enable_minify_onboarding', | |
| 671 | + 'icon' => 'devices', | |
| 672 | + 'label' => __('Lighter on every device', 'wp-optimize'), | |
| 673 | + 'summary' => __('Smaller files reach browsers faster, especially on mobile.', 'wp-optimize'), | |
| 674 | + 'details' => $details, | |
| 675 | + ); | |
| 630 | 676 | } |
| 631 | 677 | |
| 632 | 678 | /** |
| 633 | - * Get the introductory feature bullet points for 1st Step of Onboarding wizard. | |
| 679 | + * Build the image optimization feature definition for the onboarding wizard. | |
| 634 | 680 | * |
| 635 | - * @return array List of bullets with icon, title, and description. | |
| 681 | + * Covers image compression and WebP conversion. | |
| 682 | + * For premium users, it also includes lazy loading and image dimensions. | |
| 683 | + * | |
| 684 | + * @return array Feature field definition array. | |
| 636 | 685 | */ |
| 637 | - private function get_intro_bullets(): array { | |
| 686 | + private function get_image_feature(): array { | |
| 687 | + $details = __('Bundles image compression and WebP conversion.', 'wp-optimize'); | |
| 688 | + $details .= ' '.__('New uploads are compressed automatically and originals are backed up.', 'wp-optimize'); | |
| 689 | + | |
| 690 | + if ($this->is_premium) { | |
| 691 | + $details .= ' '.__('Also adds image dimensions and lazy loading to improve perceived speed.', 'wp-optimize'); | |
| 692 | + } | |
| 693 | + | |
| 694 | + $details .= ' '.__('You can change this anytime.', 'wp-optimize'); | |
| 695 | + | |
| 638 | 696 | return array( |
| 639 | - array( | |
| 640 | - 'icon' => 'database', | |
| 641 | - 'title' => __('Clean database', 'wp-optimize'), | |
| 642 | - 'desc' => __('Remove unnecessary data to keep your site fast.', 'wp-optimize'), | |
| 643 | - ), | |
| 644 | - array( | |
| 645 | - 'icon' => 'compress', | |
| 646 | - 'title' => __('Compress images', 'wp-optimize'), | |
| 647 | - 'desc' => __('Reduce image sizes for quicker page loads.', 'wp-optimize'), | |
| 648 | - ), | |
| 649 | - array( | |
| 650 | - 'icon' => 'cache', | |
| 651 | - 'title' => __('Cache pages', 'wp-optimize'), | |
| 652 | - 'desc' => __('Store pages for instant loading.', 'wp-optimize'), | |
| 653 | - ), | |
| 654 | - array( | |
| 655 | - 'icon' => 'minify', | |
| 656 | - 'title' => __('Minify code', 'wp-optimize'), | |
| 657 | - 'desc' => __('Shrink CSS, JavaScript, and HTML for better performance.', 'wp-optimize'), | |
| 658 | - ), | |
| 697 | + 'id' => 'enable_image_optimization_onboarding', | |
| 698 | + 'key' => 'enable_image_optimization_onboarding', | |
| 699 | + 'icon' => 'images', | |
| 700 | + 'label' => __('Optimised media', 'wp-optimize'), | |
| 701 | + 'summary' => __('We\'ll compress your images.', 'wp-optimize').' '.__('Same quality, faster load.', 'wp-optimize'), | |
| 702 | + 'details' => $details, | |
| 659 | 703 | ); |
| 660 | 704 | } |
| 661 | 705 | |
| 662 | 706 | /** |
| @@ -680,9 +724,9 @@ | ||
| 680 | 724 | * Initialize the onboarding |
| 681 | 725 | * |
| 682 | 726 | * @return void |
| 683 | 727 | */ |
| 684 | - public function setup_onboarding(): void { | |
| 728 | + private function setup_onboarding(): void { | |
| 685 | 729 | $onboarding = new Onboarding(); |
| 686 | 730 | if ($onboarding::is_onboarding_active($this->prefix, $this->caller_slug)) { |
| 687 | 731 | |
| 688 | 732 | $support_link = $this->is_premium ? WP_Optimize_Utils::add_utm_params('https://teamupdraft.com/support/premium-support/', $this->get_utm_params_to_override('premium-support')) : esc_url('https://wordpress.org/support/plugin/wp-optimize/'); |
| @@ -712,8 +756,17 @@ | ||
| 712 | 756 | |
| 713 | 757 | $onboarding->init(); |
| 714 | 758 | |
| 715 | 759 | } |
| 760 | + } | |
| 761 | + | |
| 762 | + /** | |
| 763 | + * Check if the onboarding wizard is currently active (i.e. its modal is/will be shown) | |
| 764 | + * | |
| 765 | + * @return bool | |
| 766 | + */ | |
| 767 | + public function is_active(): bool { | |
| 768 | + return Onboarding::is_onboarding_active($this->prefix, $this->caller_slug); | |
| 716 | 769 | } |
| 717 | 770 | |
| 718 | 771 | /** |
| 719 | 772 | * Enable the onboarding wizard for the plugin. |