backup-next.php
4 days ago
capability-icon.php
4 days ago
first-run.php
4 days ago
next-step.php
4 days ago
open-staging-site.php
4 days ago
pre-consent.php
4 days ago
progress.php
4 days ago
next-step.php
192 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The state that follows a successful capability: what just happened, where it |
| 5 | * put it, the one capability worth doing next, and a way out. |
| 6 | * |
| 7 | * Replaces WP STAGING's normal success modal for the duration of the first run, |
| 8 | * so it carries the new staging site's address and leaves out the review ask, |
| 9 | * which would land on the exact moment the first run is trying to use. Rendered |
| 10 | * hidden while the job still runs, so success lands on a screen rather than a gap. |
| 11 | * |
| 12 | * @see \WPStaging\Framework\Onboarding\OnboardingJourney |
| 13 | * |
| 14 | * @var string $completedCapability The capability whose success this announces. |
| 15 | * @var string $nextCapability The capability being offered. |
| 16 | * @var bool $isNextStepOffered False once the next capability is already under way. |
| 17 | * @var bool $isBackupInBackground The offered backup is the one parked behind the staging site. |
| 18 | * @var string $stagingSiteUrl Empty unless a staging site exists. |
| 19 | * @var array $backupDetails `name` and `size` of the backup this run created, if any. |
| 20 | * @var string $adminUrl |
| 21 | */ |
| 22 | |
| 23 | use WPStaging\Framework\Onboarding\OnboardingJourney; |
| 24 | |
| 25 | $confirmations = [ |
| 26 | OnboardingJourney::CAPABILITY_BACKUP => [ |
| 27 | 'title' => __('Your backup is ready', 'wp-staging'), |
| 28 | 'text' => __('A complete backup of your website has been created successfully.', 'wp-staging'), |
| 29 | ], |
| 30 | OnboardingJourney::CAPABILITY_STAGING => [ |
| 31 | 'title' => __('Your staging site is ready', 'wp-staging'), |
| 32 | 'text' => __('Test updates and changes safely without affecting your live website.', 'wp-staging'), |
| 33 | ], |
| 34 | ]; |
| 35 | |
| 36 | $offers = [ |
| 37 | OnboardingJourney::CAPABILITY_STAGING => [ |
| 38 | 'title' => __('Test changes safely next', 'wp-staging'), |
| 39 | 'text' => __('Create a staging copy of this site where you can test updates and changes without touching your live website.', 'wp-staging'), |
| 40 | 'cta' => __('Create a Staging Site', 'wp-staging'), |
| 41 | 'busy' => __('Starting…', 'wp-staging'), |
| 42 | 'underway' => __('Creating your staging site', 'wp-staging'), |
| 43 | 'note' => __('It is being built now. You can keep working while it finishes.', 'wp-staging'), |
| 44 | ], |
| 45 | OnboardingJourney::CAPABILITY_BACKUP => [ |
| 46 | 'title' => __('Protect your live site too', 'wp-staging'), |
| 47 | 'text' => __('Create a complete backup of this website. It runs on the server, so you can keep working.', 'wp-staging'), |
| 48 | 'cta' => __('Create Backup Now', 'wp-staging'), |
| 49 | 'busy' => __('Starting backup…', 'wp-staging'), |
| 50 | 'underway' => __('Creating your backup', 'wp-staging'), |
| 51 | 'note' => __('It runs on the server, so you can start testing your staging site.', 'wp-staging'), |
| 52 | ], |
| 53 | ]; |
| 54 | |
| 55 | if (!isset($confirmations[$completedCapability])) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | // Nothing left to offer: this capability is the second one, and finishing it |
| 60 | // finishes the first run. It still gets a state of its own rather than handing |
| 61 | // the moment back to the success modal the rest of the journey replaced. |
| 62 | $isFinale = $nextCapability === ''; |
| 63 | $offer = $isFinale ? [] : $offers[$nextCapability]; |
| 64 | |
| 65 | $confirmation = $confirmations[$completedCapability]; |
| 66 | $hasStagingSite = $completedCapability === OnboardingJourney::CAPABILITY_STAGING; |
| 67 | |
| 68 | // A backup parked behind the staging site is already running on the server, so |
| 69 | // this state confirms it and releases the user instead of describing a wait. |
| 70 | $isBackgroundBackup = !$isNextStepOffered && $isBackupInBackground; |
| 71 | $backupDone = $confirmations[OnboardingJourney::CAPABILITY_BACKUP]; |
| 72 | $background = [ |
| 73 | 'title' => __('Your backup has started', 'wp-staging'), |
| 74 | 'text' => __('It will continue in the background. You can open your staging site or return to WP STAGING now — there’s no need to wait here.', 'wp-staging'), |
| 75 | // Shown once the wait stops looking momentary. A server that cannot call |
| 76 | // itself leaves the request queued for a while before anything picks it up, |
| 77 | // and a bar with no explanation reads as a stall rather than a queue. |
| 78 | 'waiting' => __('Waiting for the server to pick it up…', 'wp-staging'), |
| 79 | ]; |
| 80 | |
| 81 | // Opening the new site is the thing to do the moment it exists, so it takes the |
| 82 | // primary action and the capability offer steps down to secondary. Without a |
| 83 | // site to open there is nothing to outrank the offer. |
| 84 | $offerButtonClass = $hasStagingSite ? 'wpstg-btn-outline' : 'wpstg-btn-primary'; |
| 85 | ?> |
| 86 | <div |
| 87 | class="wpstg-onboarding-next" |
| 88 | data-wpstg-onboarding |
| 89 | data-completed-capability="<?php echo esc_attr($completedCapability); ?>" |
| 90 | data-staging-url="<?php echo esc_url($adminUrl . 'wpstg_clone'); ?>" |
| 91 | data-backup-url="<?php echo esc_url($adminUrl . 'wpstg_backup'); ?>" |
| 92 | > |
| 93 | <div class="wpstg-onboarding-next__done"> |
| 94 | <svg class="wpstg-onboarding-next__check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"> |
| 95 | <path d="M20 6 9 17l-5-5"></path> |
| 96 | </svg> |
| 97 | </div> |
| 98 | |
| 99 | <?php if ($isFinale) : ?> |
| 100 | <h2 class="wpstg-onboarding-next__title"><?php esc_html_e('You\'re all set', 'wp-staging'); ?></h2> |
| 101 | <p class="wpstg-onboarding-next__text"><?php esc_html_e('Your website is backed up and you have a staging copy ready for safe testing.', 'wp-staging'); ?></p> |
| 102 | <?php else : ?> |
| 103 | <h2 class="wpstg-onboarding-next__title"><?php echo esc_html($confirmation['title']); ?></h2> |
| 104 | <p class="wpstg-onboarding-next__text"><?php echo esc_html($confirmation['text']); ?></p> |
| 105 | <?php endif; ?> |
| 106 | |
| 107 | <?php if (!$hasStagingSite && !empty($backupDetails['name'])) : ?> |
| 108 | <p class="wpstg-onboarding-next__where"> |
| 109 | <span class="wpstg-onboarding-next__where-label"><?php esc_html_e('Saved as', 'wp-staging'); ?></span> |
| 110 | <span class="wpstg-onboarding-next__file"><?php echo esc_html($backupDetails['name']); ?></span> |
| 111 | <?php if (!empty($backupDetails['size'])) : ?> |
| 112 | <span class="wpstg-onboarding-next__size"><?php echo esc_html(size_format($backupDetails['size'], 1)); ?></span> |
| 113 | <?php endif; ?> |
| 114 | </p> |
| 115 | <?php endif; ?> |
| 116 | |
| 117 | <?php if ($hasStagingSite || $isFinale) : ?> |
| 118 | <p class="wpstg-onboarding-next__where"> |
| 119 | <span class="wpstg-onboarding-next__where-label"><?php esc_html_e('Installed at', 'wp-staging'); ?></span> |
| 120 | <a |
| 121 | class="wpstg-onboarding-next__url" |
| 122 | data-wpstg-onboarding-site-url |
| 123 | data-wpstg-onboarding-site-url-text |
| 124 | target="_blank" |
| 125 | rel="noopener noreferrer" |
| 126 | <?php echo $stagingSiteUrl === '' ? 'hidden' : 'href="' . esc_url($stagingSiteUrl) . '"'; ?> |
| 127 | ><?php echo esc_html($stagingSiteUrl); ?></a> |
| 128 | </p> |
| 129 | |
| 130 | <?php include WPSTG_VIEWS_DIR . 'onboarding/open-staging-site.php'; ?> |
| 131 | <?php endif; ?> |
| 132 | |
| 133 | <?php if (!$isFinale) : ?> |
| 134 | <div |
| 135 | class="wpstg-onboarding-next__offer" |
| 136 | <?php if ($isBackgroundBackup) : ?> |
| 137 | data-wpstg-onboarding-backup="started" |
| 138 | data-ready-title="<?php echo esc_attr($backupDone['title']); ?>" |
| 139 | data-ready-text="<?php echo esc_attr($backupDone['text']); ?>" |
| 140 | role="status" |
| 141 | aria-live="polite" |
| 142 | <?php endif; ?> |
| 143 | > |
| 144 | <?php if ($isBackgroundBackup) : ?> |
| 145 | <h3 class="wpstg-onboarding-next__offer-title wpstg-onboarding-next__running"> |
| 146 | <span class="wpstg-onboarding-next__running-mark" aria-hidden="true"> |
| 147 | <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" focusable="false"> |
| 148 | <path d="M20 6 9 17l-5-5"></path> |
| 149 | </svg> |
| 150 | </span> |
| 151 | <span data-wpstg-onboarding-backup-title><?php echo esc_html($background['title']); ?></span> |
| 152 | </h3> |
| 153 | <p class="wpstg-onboarding-next__offer-text" data-wpstg-onboarding-backup-text><?php echo esc_html($background['text']); ?></p> |
| 154 | |
| 155 | <?php |
| 156 | // Stands in until there is a job to report on. A released backup |
| 157 | // waits for background processing to pick it up, which on a server |
| 158 | // whose loopback is slow is most of the wait — and the whole point |
| 159 | // of this state is that the wait is never silent. |
| 160 | ?> |
| 161 | <span class="wpstg-onboarding-progress__bar wpstg-onboarding-next__waiting" data-wpstg-onboarding-backup-bar aria-hidden="true"></span> |
| 162 | <p class="wpstg-onboarding-next__waiting-note" data-wpstg-onboarding-backup-waiting hidden><?php echo esc_html($background['waiting']); ?></p> |
| 163 | |
| 164 | <?php |
| 165 | // The panel the rest of WP STAGING shows for a job it watches |
| 166 | // rather than drives. It renders itself only once one is running. |
| 167 | require WPSTG_VIEWS_DIR . 'job/locked.php'; |
| 168 | ?> |
| 169 | <?php elseif (!$isNextStepOffered) : ?> |
| 170 | <h3 class="wpstg-onboarding-next__offer-title"><?php echo esc_html($offer['underway']); ?></h3> |
| 171 | <p class="wpstg-onboarding-next__offer-text"><?php echo esc_html($offer['note']); ?></p> |
| 172 | <?php else : ?> |
| 173 | <h3 class="wpstg-onboarding-next__offer-title"><?php echo esc_html($offer['title']); ?></h3> |
| 174 | <p class="wpstg-onboarding-next__offer-text"><?php echo esc_html($offer['text']); ?></p> |
| 175 | |
| 176 | <button |
| 177 | type="button" |
| 178 | class="wpstg-btn wpstg-btn-lg <?php echo esc_attr($offerButtonClass); ?> wpstg-onboarding-next__cta" |
| 179 | data-wpstg-onboarding-action="<?php echo esc_attr($nextCapability); ?>" |
| 180 | data-busy-label="<?php echo esc_attr($offer['busy']); ?>" |
| 181 | > |
| 182 | <?php echo esc_html($offer['cta']); ?> |
| 183 | </button> |
| 184 | <?php endif; ?> |
| 185 | </div> |
| 186 | <?php endif; ?> |
| 187 | |
| 188 | <button type="button" class="wpstg-onboarding-next__finish" data-wpstg-onboarding-finish> |
| 189 | <?php esc_html_e('Continue to WP STAGING', 'wp-staging'); ?> |
| 190 | </button> |
| 191 | </div> |
| 192 |