Adapter
2 months ago
Analytics
1 month ago
Assets
1 month ago
BackgroundProcessing
1 month ago
CloningProcess
4 months ago
Collection
3 years ago
Command
5 years ago
Component
8 months ago
DI
6 months ago
Database
1 month ago
DependencyResolver
2 years ago
Exceptions
2 years ago
Facades
2 months ago
Filesystem
2 months ago
Interfaces
5 years ago
Job
1 month ago
Language
3 months ago
Logger
1 month ago
Mails
3 months ago
Network
1 month ago
Newsfeed
4 months ago
Notices
1 month ago
Performance
2 months ago
Permalinks
11 months ago
Queue
4 months ago
Rest
2 months ago
Security
1 month ago
Settings
1 month ago
TemplateEngine
6 months ago
ThirdParty
5 months ago
Traits
1 month ago
Utils
2 months ago
AnalyticsServiceProvider.php
1 month ago
AssetServiceProvider.php
1 year ago
CommonServiceProvider.php
1 month ago
ErrorHandler.php
8 months ago
NoticeServiceProvider.php
11 months ago
SettingsServiceProvider.php
2 months ago
SiteInfo.php
5 months ago
Url.php
4 months ago
CommonServiceProvider.php
126 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework; |
| 4 | |
| 5 | use WPStaging\Core\Cron\Cron; |
| 6 | use WPStaging\Core\Cron\CronIntegrity; |
| 7 | use WPStaging\Framework\Analytics\AnalyticsCleanup; |
| 8 | use WPStaging\Framework\DI\ServiceProvider; |
| 9 | use WPStaging\Framework\Filesystem\DebugLogReader; |
| 10 | use WPStaging\Framework\Filesystem\DiskWriteCheck; |
| 11 | use WPStaging\Framework\Filesystem\LogCleanup; |
| 12 | use WPStaging\Framework\Mails\MailSender; |
| 13 | use WPStaging\Framework\Notices\BackupPluginsNotice; |
| 14 | use WPStaging\Framework\Notices\CliIntegrationNotice; |
| 15 | use WPStaging\Framework\Notices\WpVersionCompatNotice; |
| 16 | use WPStaging\Framework\Performance\MemoryExhaust; |
| 17 | use WPStaging\Framework\Security\Otp\Otp; |
| 18 | use WPStaging\Framework\Settings\DarkMode; |
| 19 | use WPStaging\Framework\Traits\EventLoggerTrait; |
| 20 | use WPStaging\Framework\Utils\DBPermissions; |
| 21 | use WPStaging\Staging\Ajax\StagingSiteDataChecker; |
| 22 | |
| 23 | /** |
| 24 | * Class CommonServiceProvider |
| 25 | * |
| 26 | * A Service Provider for binds common to both Free and Pro. |
| 27 | * |
| 28 | * @package WPStaging\Framework |
| 29 | */ |
| 30 | class CommonServiceProvider extends ServiceProvider |
| 31 | { |
| 32 | use EventLoggerTrait; |
| 33 | |
| 34 | protected function registerClasses() |
| 35 | { |
| 36 | $this->container->singleton(DiskWriteCheck::class); |
| 37 | $this->container->make(DebugLogReader::class)->listenDeleteLogRequest(); |
| 38 | |
| 39 | add_action(Cron::ACTION_DAILY_EVENT, [$this, 'cleanupLogs'], 25, 0); |
| 40 | add_action(Cron::ACTION_DAILY_EVENT, [$this, 'cleanupAnalytics'], 25, 0); |
| 41 | add_action(Cron::ACTION_DAILY_EVENT, [$this, 'cleanupExpiredOtps'], 25, 0); |
| 42 | |
| 43 | // Per-request cron integrity check (throttled): re-creates missing cron events (e.g. for |
| 44 | // backup schedules) even when WP-Cron itself is broken so the daily event above never fires. |
| 45 | // Priority 20 so custom recurrences registered on `init` (default priority 10) are present |
| 46 | // when wp_next_scheduled / wp_get_schedules are queried. |
| 47 | // Wrapped in try/catch: when an outdated free version is active, the DI container may |
| 48 | // resolve BackupScheduler from the free autoloader (which prepends), hitting missing |
| 49 | // classes (e.g. BackupProcessLock renamed in newer versions) and causing a fatal error. |
| 50 | $container = $this->container; |
| 51 | add_action('init', function () use ($container) { |
| 52 | // Skip during WP install (DB schema may not yet exist) and inside the WP-Cron runner |
| 53 | // itself (re-entry from within a cron tick would just do a no-op transient read). |
| 54 | if (defined('WP_INSTALLING') && WP_INSTALLING) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if (defined('DOING_CRON') && DOING_CRON) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | $container->make(CronIntegrity::class)->checkAndRepair(); |
| 64 | } catch (\Throwable $e) { |
| 65 | // Silently skip — dependency resolution failed (e.g. incompatible free version). |
| 66 | } |
| 67 | }, 20, 0); |
| 68 | add_action("wp_ajax_wpstg_is_writable_clone_destination_dir", $this->container->callback(StagingSiteDataChecker::class, "ajaxIsWritableCloneDestinationDir")); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 69 | add_action("wp_ajax_wpstg_check_user_permissions", $this->container->callback(DBPermissions::class, 'ajaxCheckDBPermissions')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 70 | add_action("wp_ajax_wpstg_check_user_is_authenticated", [$this, "ajaxIsUserAuthenticated"]);// phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 71 | add_action("wp_ajax_nopriv_wpstg_check_user_is_authenticated", [$this, "ajaxIsUserAuthenticated"]);// phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 72 | add_action('wp_ajax_wpstg_backup_plugin_notice_close', $this->container->callback(BackupPluginsNotice::class, 'ajaxBackupPluginNoticeClose')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 73 | add_action('wp_ajax_wpstg_backup_plugin_notice_remind_me', $this->container->callback(BackupPluginsNotice::class, 'ajaxBackupPluginNoticeRemindMe')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 74 | add_action('wp_ajax_wpstg_cli_notice_close', $this->container->callback(CliIntegrationNotice::class, 'ajaxCliNoticeClose')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 75 | add_action('wp_ajax_wpstg_cli_notice_hide_forever', $this->container->callback(CliIntegrationNotice::class, 'ajaxCliNoticeHideForever')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 76 | add_action('wp_ajax_wpstg_cli_get_backup_list', $this->container->callback(CliIntegrationNotice::class, 'ajaxGetCliBackupList')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 77 | add_action('admin_init', $this->container->callback(DarkMode::class, 'mayBeShowDarkMode'), 10, 1); |
| 78 | add_action('wp_ajax_wpstg_set_dark_mode', $this->container->callback(DarkMode::class, 'ajaxEnableDefaultColorMode')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 79 | add_action('wp_ajax_wpstg_set_default_os_color_mode', $this->container->callback(DarkMode::class, 'ajaxSetDefaultOsMode')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 80 | add_action("wp_ajax_wpstg_log_event_failure", [$this, "ajaxLogEventFailure"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 81 | add_action("wp_ajax_nopriv_wpstg_log_event_failure", [$this, "ajaxLogEventFailure"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 82 | add_action('wp_ajax_wpstg--detect-memory-exhaust', $this->container->callback(MemoryExhaust::class, 'ajaxResponse')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 83 | add_action("wp_ajax_wpstg_log_event_success", [$this, "ajaxLogEventSuccess"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 84 | add_action("wp_ajax_nopriv_wpstg_log_event_success", [$this, "ajaxLogEventSuccess"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 85 | add_action('wp_ajax_wpstg_send_mail_notification', $this->container->callback(MailSender::class, 'ajaxSendEmailNotification')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 86 | add_action('wp_ajax_nopriv_wpstg_send_mail_notification', $this->container->callback(MailSender::class, 'ajaxSendEmailNotification')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 87 | add_action('wp_ajax_wpstg_dismiss_compat_notice', $this->container->callback(WpVersionCompatNotice::class, 'ajaxDismissCompatNotice')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return void |
| 92 | */ |
| 93 | public function cleanupLogs() |
| 94 | { |
| 95 | $this->container->make(LogCleanup::class)->cleanOldLogs(); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @return void |
| 100 | */ |
| 101 | public function cleanupAnalytics() |
| 102 | { |
| 103 | $this->container->make(AnalyticsCleanup::class)->cleanupOldAnalytics(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return void |
| 108 | */ |
| 109 | public function cleanupExpiredOtps() |
| 110 | { |
| 111 | $this->container->make(Otp::class)->cleanupExpiredOtps(); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @return void |
| 116 | */ |
| 117 | public function ajaxIsUserAuthenticated() |
| 118 | { |
| 119 | if (!is_user_logged_in()) { |
| 120 | wp_send_json(['wpAuthCheck' => false, 'redirectUrl' => wp_login_url()]); |
| 121 | } |
| 122 | |
| 123 | wp_send_json(['wpAuthCheck' => true]); |
| 124 | } |
| 125 | } |
| 126 |