PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.2
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / AnalyticsServiceProvider.php
wp-staging / Framework Last commit date
Adapter 1 week ago Analytics 3 days ago Assets 3 days ago BackgroundProcessing 1 week ago CloningProcess 1 week ago Collection 1 week ago Command 1 week ago Component 1 week ago DI 1 week ago Database 3 days ago DependencyResolver 1 week ago Exceptions 2 years ago Experiments 1 week ago Facades 1 week ago Filesystem 1 week ago Interfaces 1 week ago Job 3 days ago Language 1 week ago Logger 3 days ago Mails 1 week ago Network 1 week ago Newsfeed 1 week ago Notices 3 days ago Onboarding 1 week ago Performance 1 week ago Permalinks 1 week ago Queue 1 week ago Rest 3 days ago Security 1 week ago Settings 3 days ago TemplateEngine 1 week ago ThirdParty 1 week ago Traits 3 days ago Upgrade 1 week ago Utils 1 week ago AnalyticsServiceProvider.php 1 week ago AssetServiceProvider.php 1 year ago CommonServiceProvider.php 1 week ago ErrorHandler.php 1 week ago NoticeServiceProvider.php 1 year ago SettingsServiceProvider.php 4 months ago SiteInfo.php 1 week ago Url.php 1 week ago
AnalyticsServiceProvider.php
121 lines
1 <?php
2
3 namespace WPStaging\Framework;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Analytics\AnalyticsConsent;
7 use WPStaging\Framework\Analytics\AnalyticsEventDto;
8 use WPStaging\Framework\Analytics\ErrorCode;
9 use WPStaging\Framework\Analytics\AnalyticsGenericEventHandler;
10 use WPStaging\Framework\Analytics\AnalyticsSender;
11 use WPStaging\Framework\DI\FeatureServiceProvider;
12 use WPStaging\Framework\Notices\Notices;
13 use WPStaging\Framework\Security\Auth;
14 use WPStaging\Framework\Utils\Cache\Cache;
15 use WPStaging\Framework\Utils\Sanitize;
16
17 class AnalyticsServiceProvider extends FeatureServiceProvider
18 {
19
20 private $sanitize;
21
22 public static function getFeatureTrigger()
23 {
24 return 'WPSTG_FEATURE_ANALYTICS';
25 }
26
27 protected function registerClasses()
28 {
29 $this->container->singleton(AnalyticsConsent::class);
30 $this->container->singleton(AnalyticsSender::class);
31 }
32
33 protected function addHooks()
34 {
35 add_action(Notices::ACTION_ADMIN_NOTICES, $this->container->callback(AnalyticsConsent::class, 'maybeShowConsentFailureNotice'));
36 add_action('admin_init', $this->container->callback(AnalyticsConsent::class, 'listenForConsent'));
37
38 $this->sanitize = WPStaging::make(Sanitize::class);
39
40
41
42
43
44
45
46
47
48 add_action("wp_ajax_wpstg_job_error", function () { // phpcs:ignore WPStaging.Security.AuthorizationChecked
49 if (empty($_POST)) {
50 return;
51 }
52
53 if (!$this->container->make(Auth::class)->isAuthenticatedRequest()) {
54 return;
55 }
56
57 foreach (['error_message', 'job_id'] as $requiredKeys) {
58 if (!isset($_POST[$requiredKeys])) {
59 return;
60 }
61 }
62
63 $errorMessage = isset($_POST['error_message']) ? $this->sanitize->htmlDecodeAndSanitize($_POST['error_message']) : '';
64
65 $jobId = isset($_POST['job_id']) ? $this->sanitize->htmlDecodeAndSanitize($_POST['job_id']) : '';
66
67 $errorCode = isset($_POST['error_code']) ? ErrorCode::sanitize($this->sanitize->htmlDecodeAndSanitize($_POST['error_code'])) : '';
68
69 AnalyticsEventDto::enqueueErrorEvent($jobId, $errorMessage, $errorCode);
70 });
71
72
73 add_action("wp_ajax_wpstg_staging_job_error", function () { // phpcs:ignore WPStaging.Security.AuthorizationChecked
74 if (empty($_POST)) {
75 return;
76 }
77
78 if (!$this->container->make(Auth::class)->isAuthenticatedRequest()) {
79 return;
80 }
81
82 foreach (['error_message'] as $requiredKeys) {
83 if (!isset($_POST[$requiredKeys])) {
84 return;
85 }
86 }
87
88
89 $errorMessage = isset($_POST['error_message']) ? $this->sanitize->htmlDecodeAndSanitize($_POST['error_message']) : '';
90
91
92
93
94
95
96 $cache = WPStaging::make(Cache::class);
97 $cache->setLifetime(-1);
98 $cache->setPath(WPStaging::getContentDir());
99
100 $options = $cache->get("clone_options");
101
102 $jobId = '';
103 if (is_object($options) && property_exists($options, 'jobIdentifier')) {
104 $jobId = $options->jobIdentifier;
105 }
106
107 if (empty($jobId)) {
108 return;
109 }
110
111 $errorCode = isset($_POST['error_code']) ? ErrorCode::sanitize($this->sanitize->htmlDecodeAndSanitize($_POST['error_code'])) : '';
112
113 AnalyticsEventDto::enqueueErrorEvent($jobId, $errorMessage, $errorCode);
114 });
115
116 add_action('wp_ajax_wpstg_event_generic', $this->container->callback(AnalyticsGenericEventHandler::class, 'ajaxHandleGenericEvent')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
117
118 $this->container->make(AnalyticsSender::class)->maybeSend();
119 }
120 }
121