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