Ajax
1 month ago
Dto
2 months ago
Interfaces
2 months ago
Jobs
5 months ago
Service
2 months ago
Tasks
1 month ago
Traits
1 month ago
CloneOptions.php
5 months ago
FirstRun.php
4 months ago
Sites.php
2 months ago
StagingServiceProvider.php
5 months ago
FirstRun.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Staging; |
| 4 | |
| 5 | use WPStaging\Frontend\LoginNotice; |
| 6 | use WPStaging\Framework\Notices\DisabledItemsNotice; |
| 7 | use WPStaging\Core\WPStaging; |
| 8 | use WPStaging\Framework\Assets\Assets; |
| 9 | use WPStaging\Framework\SiteInfo; |
| 10 | use WPStaging\Framework\ThirdParty\WordFence; |
| 11 | use WPStaging\Framework\ThirdParty\ThirdPartyCacheHandler; |
| 12 | use WPStaging\Framework\Filesystem\OPcache; |
| 13 | |
| 14 | /** |
| 15 | * Class FirstRun |
| 16 | * |
| 17 | * This class is executed only on first run when the cloned site is loaded initially |
| 18 | * |
| 19 | * @package WPStaging\Staging |
| 20 | */ |
| 21 | class FirstRun |
| 22 | { |
| 23 | /** |
| 24 | * The option_name that is stored in the database to check first run is executed or not |
| 25 | */ |
| 26 | const FIRST_RUN_KEY = 'wpstg_execute'; |
| 27 | |
| 28 | /** |
| 29 | * The option_name that is stored in the database to check whether mails are disabled or not |
| 30 | */ |
| 31 | const MAILS_DISABLED_KEY = 'wpstg_emails_disabled'; |
| 32 | |
| 33 | /** @var string */ |
| 34 | const WOO_SCHEDULER_ENABLED_KEY = 'wpstg_woo_scheduler_enabled'; |
| 35 | |
| 36 | public function init() |
| 37 | { |
| 38 | if (!(new SiteInfo())->isStagingSite()) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if (!get_option(self::FIRST_RUN_KEY)) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | $this->initActions(); |
| 47 | |
| 48 | $this->removeInitialRunOption(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Initialize actions and classes which can be hooked in by custom functions |
| 53 | * Add all classes here that you want to run on first time loading. |
| 54 | */ |
| 55 | private function initActions() |
| 56 | { |
| 57 | // Show one time login notice on staging site. |
| 58 | (new LoginNotice())->setTransient(); |
| 59 | |
| 60 | // lets delete the transient related to rest url |
| 61 | delete_transient(Assets::TRANSIENT_REST_URL); |
| 62 | |
| 63 | // Enable the notice which show what WP Staging Disabled on staging site admin. |
| 64 | WPStaging::make(DisabledItemsNotice::class)->enable(); |
| 65 | |
| 66 | // Enable the notice which show what WP Staging Disabled on staging site admin. |
| 67 | // This notice is disabled at the moment. Code below can be uncommented and notice can be tweaked if needed later. |
| 68 | // WPStaging::make(WarningsNotice::class)->enable(); |
| 69 | |
| 70 | // If user.ini present rename it to user.ini.bak and enable notice |
| 71 | (new WordFence())->renameUserIni(); |
| 72 | |
| 73 | if (class_exists('\WPStaging\Pro\Staging\NetworkClone')) { |
| 74 | (new \WPStaging\Pro\Staging\NetworkClone())->init(); |
| 75 | } |
| 76 | |
| 77 | /** @var ThirdPartyCacheHandler $cacheHandler */ |
| 78 | $cacheHandler = WPStaging::make(ThirdPartyCacheHandler::class); |
| 79 | $cacheHandler->purgeEnduranceCache(); |
| 80 | |
| 81 | // Allow users to attach custom actions by using this hook |
| 82 | do_action('wpstg.clone_first_run'); |
| 83 | |
| 84 | // Flush OPcache |
| 85 | WPStaging::make(OPcache::class)->maybeInvalidate(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Remove the first run flag from database |
| 90 | */ |
| 91 | private function removeInitialRunOption() |
| 92 | { |
| 93 | delete_option(static::FIRST_RUN_KEY); |
| 94 | } |
| 95 | } |
| 96 |