Adapter
5 months ago
Analytics
8 months ago
Assets
5 months ago
BackgroundProcessing
5 months ago
CloningProcess
5 months ago
Collection
3 years ago
Command
5 years ago
Component
8 months ago
DI
6 months ago
Database
5 months ago
DependencyResolver
2 years ago
Exceptions
2 years ago
Facades
6 months ago
Filesystem
5 months ago
Interfaces
5 years ago
Job
5 months ago
Language
5 months ago
Logger
6 months ago
Mails
6 months ago
Network
8 months ago
Newsfeed
5 months ago
Notices
5 months ago
Performance
8 months ago
Permalinks
11 months ago
Queue
8 months ago
Rest
1 year ago
Security
5 months ago
Settings
5 months ago
TemplateEngine
6 months ago
ThirdParty
5 months ago
Traits
5 months ago
Utils
5 months ago
AnalyticsServiceProvider.php
11 months ago
AssetServiceProvider.php
1 year ago
CommonServiceProvider.php
6 months ago
ErrorHandler.php
8 months ago
NoticeServiceProvider.php
11 months ago
SettingsServiceProvider.php
2 years ago
SiteInfo.php
5 months ago
Url.php
3 years ago
CommonServiceProvider.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework; |
| 4 | |
| 5 | use WPStaging\Core\Cron\Cron; |
| 6 | use WPStaging\Framework\Analytics\AnalyticsCleanup; |
| 7 | use WPStaging\Framework\DI\ServiceProvider; |
| 8 | use WPStaging\Framework\Filesystem\DebugLogReader; |
| 9 | use WPStaging\Framework\Filesystem\DiskWriteCheck; |
| 10 | use WPStaging\Framework\Filesystem\LogCleanup; |
| 11 | use WPStaging\Framework\Mails\MailSender; |
| 12 | use WPStaging\Framework\Notices\BackupPluginsNotice; |
| 13 | use WPStaging\Framework\Notices\CliIntegrationNotice; |
| 14 | use WPStaging\Framework\Performance\MemoryExhaust; |
| 15 | use WPStaging\Framework\Security\Otp\Otp; |
| 16 | use WPStaging\Framework\Settings\DarkMode; |
| 17 | use WPStaging\Framework\Traits\EventLoggerTrait; |
| 18 | use WPStaging\Framework\Utils\DBPermissions; |
| 19 | use WPStaging\Staging\Ajax\StagingSiteDataChecker; |
| 20 | |
| 21 | /** |
| 22 | * Class CommonServiceProvider |
| 23 | * |
| 24 | * A Service Provider for binds common to both Free and Pro. |
| 25 | * |
| 26 | * @package WPStaging\Framework |
| 27 | */ |
| 28 | class CommonServiceProvider extends ServiceProvider |
| 29 | { |
| 30 | use EventLoggerTrait; |
| 31 | |
| 32 | protected function registerClasses() |
| 33 | { |
| 34 | $this->container->singleton(DiskWriteCheck::class); |
| 35 | $this->container->make(DebugLogReader::class)->listenDeleteLogRequest(); |
| 36 | |
| 37 | add_action(Cron::ACTION_DAILY_EVENT, [$this, 'cleanupLogs'], 25, 0); |
| 38 | add_action(Cron::ACTION_DAILY_EVENT, [$this, 'cleanupAnalytics'], 25, 0); |
| 39 | add_action(Cron::ACTION_DAILY_EVENT, [$this, 'cleanupExpiredOtps'], 25, 0); |
| 40 | add_action("wp_ajax_wpstg_is_writable_clone_destination_dir", $this->container->callback(StagingSiteDataChecker::class, "ajaxIsWritableCloneDestinationDir")); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 41 | add_action("wp_ajax_wpstg_check_user_permissions", $this->container->callback(DBPermissions::class, 'ajaxCheckDBPermissions')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 42 | add_action("wp_ajax_wpstg_check_user_is_authenticated", [$this, "ajaxIsUserAuthenticated"]);// phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 43 | add_action("wp_ajax_nopriv_wpstg_check_user_is_authenticated", [$this, "ajaxIsUserAuthenticated"]);// phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 44 | add_action('wp_ajax_wpstg_backup_plugin_notice_close', $this->container->callback(BackupPluginsNotice::class, 'ajaxBackupPluginNoticeClose')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 45 | add_action('wp_ajax_wpstg_backup_plugin_notice_remind_me', $this->container->callback(BackupPluginsNotice::class, 'ajaxBackupPluginNoticeRemindMe')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 46 | add_action('wp_ajax_wpstg_cli_notice_close', $this->container->callback(CliIntegrationNotice::class, 'ajaxCliNoticeClose')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 47 | add_action('wp_ajax_wpstg_cli_get_backup_list', $this->container->callback(CliIntegrationNotice::class, 'ajaxGetCliBackupList')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 48 | add_action('admin_init', $this->container->callback(DarkMode::class, 'mayBeShowDarkMode'), 10, 1); |
| 49 | add_action('wp_ajax_wpstg_set_dark_mode', $this->container->callback(DarkMode::class, 'ajaxEnableDefaultColorMode')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 50 | add_action('wp_ajax_wpstg_set_default_os_color_mode', $this->container->callback(DarkMode::class, 'ajaxSetDefaultOsMode')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 51 | add_action("wp_ajax_wpstg_log_event_failure", [$this, "ajaxLogEventFailure"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 52 | add_action("wp_ajax_nopriv_wpstg_log_event_failure", [$this, "ajaxLogEventFailure"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 53 | add_action('wp_ajax_wpstg--detect-memory-exhaust', $this->container->callback(MemoryExhaust::class, 'ajaxResponse')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 54 | add_action("wp_ajax_wpstg_log_event_success", [$this, "ajaxLogEventSuccess"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 55 | add_action("wp_ajax_nopriv_wpstg_log_event_success", [$this, "ajaxLogEventSuccess"]); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 56 | add_action('wp_ajax_wpstg_send_mail_notification', $this->container->callback(MailSender::class, 'ajaxSendEmailNotification')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 57 | add_action('wp_ajax_nopriv_wpstg_send_mail_notification', $this->container->callback(MailSender::class, 'ajaxSendEmailNotification')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return void |
| 62 | */ |
| 63 | public function cleanupLogs() |
| 64 | { |
| 65 | $this->container->make(LogCleanup::class)->cleanOldLogs(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return void |
| 70 | */ |
| 71 | public function cleanupAnalytics() |
| 72 | { |
| 73 | $this->container->make(AnalyticsCleanup::class)->cleanupOldAnalytics(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return void |
| 78 | */ |
| 79 | public function cleanupExpiredOtps() |
| 80 | { |
| 81 | $this->container->make(Otp::class)->cleanupExpiredOtps(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @return void |
| 86 | */ |
| 87 | public function ajaxIsUserAuthenticated() |
| 88 | { |
| 89 | if (!is_user_logged_in()) { |
| 90 | wp_send_json(['wpAuthCheck' => false, 'redirectUrl' => wp_login_url()]); |
| 91 | } |
| 92 | |
| 93 | wp_send_json(['wpAuthCheck' => true]); |
| 94 | } |
| 95 | } |
| 96 |