BackupPluginsDetector.php
1 week ago
FirstInstall.php
1 week ago
FreeOnboarding.php
1 week ago
NextStepRenderer.php
1 week ago
OnboardingAjax.php
1 week ago
OnboardingJourney.php
1 week ago
QueuedBackup.php
1 week ago
FirstInstall.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Onboarding; |
| 4 | |
| 5 | use WPStaging\Staging\Sites; |
| 6 | |
| 7 | /** |
| 8 | * Records whether an activation is the first WP STAGING has ever seen on this site. |
| 9 | * |
| 10 | * The marker is written only when the activation finds no WP STAGING footprint |
| 11 | * at all, which is what keeps first-run experiences away from a user who merely |
| 12 | * reactivates or upgrades: their activation ran long before the marker existed. |
| 13 | */ |
| 14 | class FirstInstall |
| 15 | { |
| 16 | /** @var string UNIX timestamp of the first ever activation on this site. */ |
| 17 | const OPTION_FIRST_INSTALL = 'wpstg_first_install'; |
| 18 | |
| 19 | /** |
| 20 | * Options only a previous run can have left behind; any one means this is not |
| 21 | * a first install. `wpstg_settings` is deliberately absent — booting the |
| 22 | * plugin writes it before this check runs, so it is present on fresh installs. |
| 23 | * |
| 24 | * @var string[] |
| 25 | */ |
| 26 | const FOOTPRINT_OPTIONS = [ |
| 27 | 'wpstg_installDate', |
| 28 | 'wpstg_free_install_date', |
| 29 | 'wpstgpro_install_date', |
| 30 | 'wpstg_version', |
| 31 | Sites::STAGING_SITES_OPTION, |
| 32 | ]; |
| 33 | |
| 34 | /** |
| 35 | * Must run at the very top of the activation routine, before WP STAGING |
| 36 | * writes any of its own options. |
| 37 | * |
| 38 | * @return bool Whether this activation was a first install. |
| 39 | */ |
| 40 | public static function markIfFirstInstall(): bool |
| 41 | { |
| 42 | if (get_option(self::OPTION_FIRST_INSTALL) !== false) { |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | foreach (self::FOOTPRINT_OPTIONS as $option) { |
| 47 | if (get_option($option) !== false) { |
| 48 | return false; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | add_option(self::OPTION_FIRST_INSTALL, (string)time(), '', false); |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | public function isFirstInstall(): bool |
| 58 | { |
| 59 | return get_option(self::OPTION_FIRST_INSTALL) !== false; |
| 60 | } |
| 61 | } |
| 62 |