| 1 |
<?php |
| 2 |
|
| 3 |
use Updraftplus\Wp_Optimize\Wizard\Onboarding\Onboarding; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 6 |
|
| 7 |
require_once(WPO_PLUGIN_MAIN_PATH . 'vendor/team-updraft/lib-onboarding-wizard/autoload.php'); |
| 8 |
|
| 9 |
/** |
| 10 |
* Class WPO_Onboarding |
| 11 |
*/ |
| 12 |
class WPO_Onboarding { |
| 13 |
|
| 14 |
const MAILING_LIST_FREE_ID = 132; |
| 15 |
|
| 16 |
const MAILING_LIST_PREMIUM_ID = 133; |
| 17 |
|
| 18 |
const MAILING_LIST_ENDPOINT = 'https://teamupdraft.com/?fluentcrm=1&route=contact&hash=69902751-58c5-460b-bd9f-456d62033c2b'; |
| 19 |
|
| 20 |
private $is_premium = false; |
| 21 |
|
| 22 |
private $prefix = 'wp-optimize'; |
| 23 |
|
| 24 |
private $caller_slug = 'wp-optimize'; |
| 25 |
|
| 26 |
private $upgrade_url = ''; |
| 27 |
|
| 28 |
private $is_multisite; |
| 29 |
|
| 30 |
/** |
| 31 |
* Private constructor to prevent direct instantiation |
| 32 |
*/ |
| 33 |
private function __construct() { |
| 34 |
$this->is_premium = WP_Optimize::is_premium(); |
| 35 |
$this->is_multisite = is_multisite(); |
| 36 |
|
| 37 |
if ($this->is_multisite) { |
| 38 |
$this->prefix = 'wp-optimize-mu'; |
| 39 |
} |
| 40 |
$this->upgrade_url = WP_Optimize()->premium_version_link; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Get a singleton instance |
| 45 |
* |
| 46 |
* @return WPO_Onboarding |
| 47 |
*/ |
| 48 |
public static function instance(): WPO_Onboarding { |
| 49 |
static $instance = null; |
| 50 |
if (null === $instance) { |
| 51 |
$instance = new self(); |
| 52 |
} |
| 53 |
return $instance; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Setup hooks. |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public function init(): void { |
| 62 |
|
| 63 |
add_action( $this->prefix.'_onboarding_update_options', array($this, 'update_step_settings'), 10, 2 ); |
| 64 |
add_filter( $this->prefix.'_onboarding_steps', array($this, 'load_steps')); |
| 65 |
|
| 66 |
$this->setup_onboarding(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get Features Status |
| 71 |
* |
| 72 |
* @param array $settings Settings data |
| 73 |
* @param array $step_fields Step Fields data |
| 74 |
* |
| 75 |
* @return void |
| 76 |
*/ |
| 77 |
public function update_step_settings(array $settings, array $step_fields): void { |
| 78 |
$step_ids = array_flip(array_column($step_fields, 'id')); |
| 79 |
|
| 80 |
if (empty($settings)) { |
| 81 |
return; |
| 82 |
} |
| 83 |
foreach ($settings as $setting) { |
| 84 |
if (empty($setting['id'])) continue; |
| 85 |
|
| 86 |
if (!isset($step_ids[$setting['id']])) continue; |
| 87 |
|
| 88 |
$is_lock = isset($setting['is_lock']) ? (bool) $setting['is_lock'] : false; |
| 89 |
if ($is_lock) { |
| 90 |
continue; |
| 91 |
} |
| 92 |
|
| 93 |
$id = (string) $setting['id']; |
| 94 |
$value = isset($setting['value']) ? (bool) $setting['value'] : false; |
| 95 |
|
| 96 |
if ('enable_caching_onboarding' === $id) { |
| 97 |
$wpo_page_cache = WP_Optimize()->get_page_cache(); |
| 98 |
|
| 99 |
if (true === $value) { |
| 100 |
$wpo_page_cache->enable(true); |
| 101 |
} else { |
| 102 |
$wpo_page_cache->disable(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
if ('enable_minify_onboarding' === $id) { |
| 107 |
wp_optimize_minify_config()->update(array('enabled' => $value)); |
| 108 |
} |
| 109 |
|
| 110 |
if ('enable_image_compression_onboarding' === $id) { |
| 111 |
Updraft_Smush_Manager()->update_smush_options(array('autosmush' => $value)); |
| 112 |
} |
| 113 |
|
| 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 |
} |
| 119 |
|
| 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 |
} |
| 131 |
|
| 132 |
if ('enable_image_dimensions_onboarding' === $id) { |
| 133 |
WP_Optimize()->get_options()->update_option('image_dimensions', (int) $value); |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Load the steps for the onboarding process. |
| 140 |
* |
| 141 |
* Builds and returns the steps depending on the user's |
| 142 |
* premium status and license connection. |
| 143 |
* |
| 144 |
* @param array $steps Unused parameter for compatibility. |
| 145 |
* |
| 146 |
* @return array Ordered an array of steps for the onboarding wizard. |
| 147 |
*/ |
| 148 |
public function load_steps($steps = array()): array { |
| 149 |
// Build steps |
| 150 |
$steps = array(); // To override all previous steps. |
| 151 |
|
| 152 |
// Step 1: Intro |
| 153 |
$steps[] = $this->intro_step(); |
| 154 |
|
| 155 |
// Step 2: License step (only for premium users without a connected license) |
| 156 |
if ($this->should_add_license_step()) { |
| 157 |
$steps[] = $this->license_step(); |
| 158 |
} |
| 159 |
|
| 160 |
// Step 3: Feature settings |
| 161 |
$steps[] = $this->features_step(); |
| 162 |
|
| 163 |
// Step 4: Newsletter signup |
| 164 |
$steps[] = $this->newsletter_step(); |
| 165 |
|
| 166 |
// Step 5: Recommended plugins |
| 167 |
$steps[] = $this->plugins_install_step(); |
| 168 |
|
| 169 |
// Step 6: Go Premium step (only for non-premium users) |
| 170 |
if (!$this->is_premium) { |
| 171 |
$steps[] = $this->go_premium_step(); |
| 172 |
} |
| 173 |
|
| 174 |
// Step 7: Final step |
| 175 |
$steps[] = $this->last_step(); |
| 176 |
|
| 177 |
return $steps; |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Determine if the license step should be added. |
| 182 |
* |
| 183 |
* @return bool True if the plugin is premium but the license is not connected. |
| 184 |
*/ |
| 185 |
private function should_add_license_step(): bool { |
| 186 |
return $this->is_premium && !$this->is_license_connected(); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 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 |
* Build the license activation step for the onboarding wizard. |
| 221 |
* |
| 222 |
* This step includes fields for email and password, conditional |
| 223 |
* titles/subtitles based on license status, and a button to |
| 224 |
* activate the license. |
| 225 |
* |
| 226 |
* @return array Step configuration including ID, type, icon, titles, subtitles, fields, and button info. |
| 227 |
*/ |
| 228 |
private function license_step(): array { |
| 229 |
return array( |
| 230 |
'id' => 'license', |
| 231 |
'type' => 'license', |
| 232 |
'icon' => 'user-lock', |
| 233 |
'title' => __('Connect and activate your license', 'wp-optimize'), |
| 234 |
'title_conditional' => array( |
| 235 |
'licenseActivated' => __('License activated!', 'wp-optimize'), |
| 236 |
'isUpdating' => __('Activating your Premium license...', 'wp-optimize'), |
| 237 |
), |
| 238 |
'subtitle' => __('Please enter your TeamUpdraft credentials to start using Premium features.', 'wp-optimize'), |
| 239 |
'subtitle_conditional' => array( |
| 240 |
'licenseActivated' => '', |
| 241 |
'isUpdating' => '', |
| 242 |
), |
| 243 |
'fields' => array( |
| 244 |
array( |
| 245 |
'id' => 'registration_email', |
| 246 |
'type' => 'email', |
| 247 |
'label' => __('Email', 'wp-optimize'), |
| 248 |
), |
| 249 |
array( |
| 250 |
'id' => 'registration_password', |
| 251 |
'type' => 'password', |
| 252 |
'label' => __('Password', 'wp-optimize'), |
| 253 |
), |
| 254 |
), |
| 255 |
'button' => array( |
| 256 |
'id' => 'activate', |
| 257 |
'label'=> __('Confirm and activate', 'wp-optimize'), |
| 258 |
'icon' => 'EastRoundedIcon', |
| 259 |
) |
| 260 |
); |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Build the step for the best-practice features in the onboarding wizard. |
| 265 |
* |
| 266 |
* @return array Step data including title, subtitle, feature fields, button info, and skip step info. |
| 267 |
*/ |
| 268 |
private function features_step(): array { |
| 269 |
$features = $this->get_feature_settings(); |
| 270 |
return array( |
| 271 |
'id' => 'page_features', |
| 272 |
'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'), |
| 276 |
'fields' => $features, |
| 277 |
'button' => array( |
| 278 |
'id' => 'save', |
| 279 |
'label'=> __('Save and continue', 'wp-optimize'), |
| 280 |
'icon' => 'EastRoundedIcon', |
| 281 |
), |
| 282 |
'skip_step' => array( |
| 283 |
'icon' => 'info', |
| 284 |
'tooltip' => array( |
| 285 |
'text' => __('All above features will be disabled if you skip.', 'wp-optimize'), |
| 286 |
), |
| 287 |
) |
| 288 |
); |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Build the step for a newsletter in the onboarding wizard. |
| 293 |
* |
| 294 |
* @return array Step data including title, subtitle, email fields, and button info. |
| 295 |
*/ |
| 296 |
private function newsletter_step(): array { |
| 297 |
$email_fields = $this->get_email_fields(); |
| 298 |
return array( |
| 299 |
'id' => 'email', |
| 300 |
'type' => 'email', |
| 301 |
'icon' => 'mail', |
| 302 |
'title' => __('Get lightning-fast insights!', 'wp-optimize'), |
| 303 |
'subtitle' => __('Join our newsletter for speed-optimization tips and best practices.', 'wp-optimize').' '.__('Delivered straight to your inbox.', 'wp-optimize'), |
| 304 |
'fields' => $email_fields, |
| 305 |
'button' => array( |
| 306 |
'id' => 'save', |
| 307 |
'label'=> __('Save and continue', 'wp-optimize'), |
| 308 |
'icon' => 'EastRoundedIcon', |
| 309 |
), |
| 310 |
); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Build the step for the recommended plugins installation in the onboarding wizard. |
| 315 |
* |
| 316 |
* @return array Step data including title, subtitle, plugin fields, and button info. |
| 317 |
*/ |
| 318 |
private function plugins_install_step(): array { |
| 319 |
return array( |
| 320 |
'id' => 'plugins', |
| 321 |
'type' => 'plugins', |
| 322 |
'icon' => 'plugin', |
| 323 |
'first_run_only' => false, |
| 324 |
'title' => __('Recommended for your setup', 'wp-optimize'), |
| 325 |
'title_conditional' => array( |
| 326 |
'all_installed' => __('Best-practice plugins enabled', 'wp-optimize'), |
| 327 |
), |
| 328 |
'subtitle' => __('We\'ve carefully handpicked these plugins to match your website\'s setup, so everything works just the way it should.', 'wp-optimize'), |
| 329 |
'subtitle_conditional' => array( |
| 330 |
'all_installed' => __('Wow, your site already meets all our plugin recommendations, let\'s move on!', 'wp-optimize'), |
| 331 |
), |
| 332 |
'fields' => array( |
| 333 |
array( |
| 334 |
'id' => 'plugins', |
| 335 |
'type' => 'plugins', |
| 336 |
), |
| 337 |
), |
| 338 |
'button' => array( |
| 339 |
'id' => 'save', |
| 340 |
'label' => __('Install and continue', 'wp-optimize'), |
| 341 |
'icon' => 'EastRoundedIcon', |
| 342 |
), |
| 343 |
); |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Build the "Go Premium" onboarding step array. |
| 348 |
* |
| 349 |
* @return array Step data including title, subtitle, bullets, and button info. |
| 350 |
*/ |
| 351 |
private function go_premium_step(): array { |
| 352 |
$go_premium_step_bullets = $this->get_go_premium_bullets(); |
| 353 |
return array( |
| 354 |
'id' => 'go_premium', |
| 355 |
'type' => 'go_premium', |
| 356 |
'icon' => 'bolt', |
| 357 |
'title' => __('Upgrade to Premium', 'wp-optimize'), |
| 358 |
'subtitle' => __('The complete optimization suite with safe defaults and expert help.', 'wp-optimize'), |
| 359 |
'bullets' => $go_premium_step_bullets, |
| 360 |
'enable_premium_btn' => true, |
| 361 |
'premium_btn_text' => __('Upgrade to Premium', 'wp-optimize'), |
| 362 |
); |
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* Build the final "Completed" onboarding step array. |
| 367 |
* |
| 368 |
* @return array Step data including title, subtitle, bullets, and finish button info. |
| 369 |
*/ |
| 370 |
private function last_step(): array { |
| 371 |
list($last_step_subtitle, $last_step_subtitle_is_installing) = $this->get_last_step_subtitles(); |
| 372 |
|
| 373 |
$last_step_bullets = $this->get_last_step_bullets(); |
| 374 |
|
| 375 |
return array( |
| 376 |
'id' => 'completed', |
| 377 |
'type' => 'completed', |
| 378 |
'icon' => 'CheckRoundedIcon', |
| 379 |
'title' => __('You\'re all set!', 'wp-optimize'), |
| 380 |
'title_conditional' => array( |
| 381 |
'isInstalling' => __('Almost done, finalizing...', 'wp-optimize'), |
| 382 |
), |
| 383 |
'subtitle' => $last_step_subtitle, |
| 384 |
'subtitle_conditional' => array( |
| 385 |
'isInstalling' => $last_step_subtitle_is_installing |
| 386 |
), |
| 387 |
'bullets' => $last_step_bullets, |
| 388 |
'button' => array( |
| 389 |
'id' => 'finish', |
| 390 |
'label' => __('Go to settings', 'wp-optimize'), |
| 391 |
), |
| 392 |
); |
| 393 |
} |
| 394 |
|
| 395 |
/** |
| 396 |
* Check if the plugin license is connected via the Updraft updater instance. |
| 397 |
* |
| 398 |
* @return bool True if the license is connected, false otherwise. |
| 399 |
*/ |
| 400 |
private function is_license_connected(): bool { |
| 401 |
global $updraft_updater_instance; |
| 402 |
|
| 403 |
if (!isset($updraft_updater_instance)) { |
| 404 |
return false; |
| 405 |
} |
| 406 |
|
| 407 |
return (bool) $updraft_updater_instance->is_connected(); |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Get bullet points for the "Go Premium" step. |
| 412 |
* |
| 413 |
* Each bullet highlights a benefit of upgrading to the Premium version. |
| 414 |
* |
| 415 |
* @return array Array of bullet strings, each wrapped in its own array. |
| 416 |
*/ |
| 417 |
private function get_go_premium_bullets(): array { |
| 418 |
return array( |
| 419 |
array( |
| 420 |
__('Ranking high', 'wp-optimize') |
| 421 |
), |
| 422 |
array( |
| 423 |
__('Loading at top speed', 'wp-optimize') |
| 424 |
), |
| 425 |
array( |
| 426 |
__('Turning more visits into sales', 'wp-optimize'), |
| 427 |
), |
| 428 |
array( |
| 429 |
__('Serving visitors & customers better', 'wp-optimize'), |
| 430 |
), |
| 431 |
); |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* Get subtitles for the last onboarding step. |
| 436 |
* |
| 437 |
* Provides two strings: |
| 438 |
* 1. Standard subtitle for the completed step. |
| 439 |
* 2. Subtitle showed when redirecting to settings (with a link to the plugin page). |
| 440 |
* |
| 441 |
* @return array Array containing two strings: [standard_subtitle, installing_subtitle]. |
| 442 |
*/ |
| 443 |
private function get_last_step_subtitles(): array { |
| 444 |
|
| 445 |
$subtitle = __('WP-Optimize is ready to help your site run faster.', 'wp-optimize'); |
| 446 |
$subtitle .= ' '; |
| 447 |
$subtitle .= __('You can review or customize settings whenever you like.', 'wp-optimize'); |
| 448 |
|
| 449 |
$installing = __('Setting things up in the background...', 'wp-optimize') . '<br>'; |
| 450 |
$installing .= __('This will only take a moment.', 'wp-optimize'); |
| 451 |
|
| 452 |
return array($subtitle, $installing); |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* Get the list of feature bullets shown in the final onboarding step. |
| 457 |
* |
| 458 |
* Returns premium-only feature bullet points. |
| 459 |
* If the user is not premium, an empty array is returned. |
| 460 |
* |
| 461 |
* @return array List of bullet point groups. |
| 462 |
*/ |
| 463 |
private function get_last_step_bullets(): array { |
| 464 |
if (!$this->is_premium) { |
| 465 |
return array(); |
| 466 |
} |
| 467 |
|
| 468 |
return array( |
| 469 |
array( |
| 470 |
__('Lazy loading', 'wp-optimize'), |
| 471 |
__('Remove unused images', 'wp-optimize'), |
| 472 |
), |
| 473 |
array( |
| 474 |
__('Multisite optimization', 'wp-optimize'), |
| 475 |
__('Preload key requests', 'wp-optimize'), |
| 476 |
), |
| 477 |
array( |
| 478 |
__('User and role-based cache', 'wp-optimize'), |
| 479 |
__('Premium support and more', 'wp-optimize'), |
| 480 |
), |
| 481 |
); |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* Get email-related form fields for the onboarding wizard. |
| 486 |
* |
| 487 |
* Returns configuration for email input and consent checkbox fields. |
| 488 |
* |
| 489 |
* @return array List of email field definitions. |
| 490 |
*/ |
| 491 |
private function get_email_fields(): array { |
| 492 |
return array( |
| 493 |
array( |
| 494 |
'id' => 'email_reports_mailinglist', |
| 495 |
'key' => 'email_reports_mailinglist', |
| 496 |
'type' => 'email', |
| 497 |
'label' => __('Email', 'wp-optimize'), |
| 498 |
'default' => '', |
| 499 |
), |
| 500 |
array( |
| 501 |
'id' => 'tips_tricks_mailinglist', |
| 502 |
'key' => 'tips_tricks_mailinglist', |
| 503 |
'type' => 'checkbox', |
| 504 |
'label' => __('I agree to receive emails with tips, updates and marketing content.', 'wp-optimize').' '.__('I understand I can unsubscribe at any time.', 'wp-optimize'), |
| 505 |
'default' => false, |
| 506 |
'show_privacy_link' => true, |
| 507 |
), |
| 508 |
); |
| 509 |
} |
| 510 |
|
| 511 |
/** |
| 512 |
* Get the list of feature settings for the onboarding wizard. |
| 513 |
* |
| 514 |
* Generates an array of feature configuration options, including |
| 515 |
* labels, types, defaults, and premium-locked items. |
| 516 |
* |
| 517 |
* @return array List of feature setting definitions. |
| 518 |
*/ |
| 519 |
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 |
} |
| 526 |
|
| 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; |
| 530 |
|
| 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']; |
| 535 |
} |
| 536 |
|
| 537 |
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 |
), |
| 613 |
); |
| 614 |
} |
| 615 |
|
| 616 |
/** |
| 617 |
* Get the tooltip heading and text for premium-only features. |
| 618 |
* |
| 619 |
* @return array An array with two values: heading and tooltip text. |
| 620 |
*/ |
| 621 |
private function get_premium_tooltip(): array { |
| 622 |
$heading = __('Premium feature ⚡', 'wp-optimize'); |
| 623 |
|
| 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>'); |
| 628 |
|
| 629 |
return array($heading, $text); |
| 630 |
} |
| 631 |
|
| 632 |
/** |
| 633 |
* Get the introductory feature bullet points for 1st Step of Onboarding wizard. |
| 634 |
* |
| 635 |
* @return array List of bullets with icon, title, and description. |
| 636 |
*/ |
| 637 |
private function get_intro_bullets(): array { |
| 638 |
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 |
), |
| 659 |
); |
| 660 |
} |
| 661 |
|
| 662 |
/** |
| 663 |
* Array of UTM parameters for the onboarding wizard. |
| 664 |
* |
| 665 |
* @param string $content UTM content. |
| 666 |
* @param string $format UTM creative_format. |
| 667 |
* |
| 668 |
* @return array |
| 669 |
*/ |
| 670 |
private function get_utm_params_to_override($content = 'onboarding', $format = 'text'): array { |
| 671 |
$type = $this->is_premium ? 'prem' : 'free'; |
| 672 |
return array( |
| 673 |
'utm_content' => $content, |
| 674 |
'utm_campaign' => sprintf('paac-%s-onboarding-wizard', $type), |
| 675 |
'utm_creative_format' => $format, |
| 676 |
); |
| 677 |
} |
| 678 |
|
| 679 |
/** |
| 680 |
* Initialize the onboarding |
| 681 |
* |
| 682 |
* @return void |
| 683 |
*/ |
| 684 |
public function setup_onboarding(): void { |
| 685 |
$onboarding = new Onboarding(); |
| 686 |
if ($onboarding::is_onboarding_active($this->prefix, $this->caller_slug)) { |
| 687 |
|
| 688 |
$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/'); |
| 689 |
|
| 690 |
$onboarding->is_pro = $this->is_premium; |
| 691 |
$onboarding->logo_path = esc_url(trailingslashit(WPO_PLUGIN_URL) . 'images/notices/wp_optimize_logo.png'); |
| 692 |
$onboarding->prefix = $this->prefix; |
| 693 |
$onboarding->plugin_name = $this->is_premium ? 'WP-Optimize Premium' : 'WP-Optimize'; |
| 694 |
$onboarding->mailing_list = array($this->is_premium ? self::MAILING_LIST_PREMIUM_ID : self::MAILING_LIST_FREE_ID); |
| 695 |
$onboarding->mailing_list_endpoint = self::MAILING_LIST_ENDPOINT; |
| 696 |
$onboarding->caller_slug = $this->caller_slug; |
| 697 |
$onboarding->capability = $this->is_multisite ? 'manage_network_options' : 'manage_options'; |
| 698 |
$onboarding->support_url = $support_link; |
| 699 |
$onboarding->privacy_url_label = __('Privacy Policy.', 'wp-optimize'); |
| 700 |
$onboarding->privacy_statement_url = WP_Optimize_Utils::add_utm_params('https://teamupdraft.com/privacy/', $this->get_utm_params_to_override('privacy-statement')); |
| 701 |
$onboarding->forgot_password_url = WP_Optimize_Utils::add_utm_params('https://teamupdraft.com/my-account/lost-password/', $this->get_utm_params_to_override('forgot-password')); |
| 702 |
$onboarding->documentation_url = WP_Optimize_Utils::add_utm_params('https://teamupdraft.com/documentation/wp-optimize/', $this->get_utm_params_to_override('documentation')); |
| 703 |
$onboarding->upgrade_url = WP_Optimize_Utils::add_utm_params($this->upgrade_url, $this->get_utm_params_to_override('upgrade-to-premium', 'button'), true); |
| 704 |
$onboarding->page_prefix = $this->caller_slug; |
| 705 |
$onboarding->version = WPO_VERSION; |
| 706 |
$onboarding->languages_dir = WPO_PLUGIN_MAIN_PATH . 'languages'; |
| 707 |
$onboarding->text_domain = 'wp-optimize'; |
| 708 |
$onboarding->exit_wizard_text = __('Exit setup', 'wp-optimize'); |
| 709 |
$onboarding->reload_settings_page_on_finish = true; |
| 710 |
$onboarding->udmupdater_muid = 2; |
| 711 |
$onboarding->udmupdater_slug = 'wp-optimize-premium'; |
| 712 |
|
| 713 |
$onboarding->init(); |
| 714 |
|
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
/** |
| 719 |
* Enable the onboarding wizard for the plugin. |
| 720 |
* |
| 721 |
* This method performs two actions: |
| 722 |
* |
| 723 |
* 1. Sets an option using site option functions, so it works for both single and multisite to trigger the onboarding |
| 724 |
* wizard the next time a WP-Optimize page loads. |
| 725 |
* 2. Removes the installation source flag, ensuring that the plugin does not |
| 726 |
* treat the current activation as originating from the onboarding wizard. |
| 727 |
* |
| 728 |
* WordPress Internally, uses the site wrappers for update_option() and delete_option() |
| 729 |
* to ensure compatibility with both single-site and multisite environments. |
| 730 |
* |
| 731 |
* @return void |
| 732 |
*/ |
| 733 |
public function activate_onboarding_wizard(): void { |
| 734 |
// to enable onboarding wizard on WP-Optimize pages |
| 735 |
update_site_option($this->prefix.'_start_onboarding', true); |
| 736 |
|
| 737 |
// to reset that this plugin was installed from the onboarding wizard |
| 738 |
delete_site_option('teamupdraft_installation_source_'.$this->caller_slug); |
| 739 |
} |
| 740 |
} |
| 741 |
|