PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.18
Independent Analytics – WordPress Analytics Plugin v1.18
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / health_check.php
independent-analytics / IAWP Last commit date
Migrations 3 years ago ajax 3 years ago models 3 years ago queries 3 years ago sql 3 years ago tables 3 years ago utils 3 years ago campaign_builder.php 3 years ago capability_manager.php 3 years ago chart.php 3 years ago chart_geo.php 3 years ago chart_svg.php 3 years ago current_resource.php 3 years ago dashboard_options.php 3 years ago dashboard_widget.php 3 years ago email_reports.php 3 years ago filters.php 3 years ago freemius.php 3 years ago geo_database.php 3 years ago geo_database_download_job.php 3 years ago health_check.php 3 years ago independent_analytics.php 3 years ago known_referrers.php 3 years ago pdf.php 3 years ago query.php 3 years ago quick_stats.php 3 years ago real_time.php 3 years ago rest_api.php 3 years ago settings.php 3 years ago track_resource_changes.php 3 years ago view_counter.php 3 years ago
health_check.php
122 lines
1 <?php
2
3 namespace IAWP;
4
5 class Health_Check
6 {
7 const REST_LAST_HEALTHY_AT = 'iawp_rest_last_healthy_at';
8 private $error = null;
9
10 public function __construct()
11 {
12 $this->error = $this->plugin_health_check();
13
14 // Only run the rest check if the plugin checks have passed
15 if (!isset($this->error) && $this->should_run_rest_health_check()) {
16 $rest_error = $this->rest_health_check();
17
18 if (isset($rest_error)) {
19 $this->error = $rest_error;
20 $this->update_wp_option(false);
21 } else {
22 $this->update_wp_option(true);
23 }
24 }
25 }
26
27 public function healthy(): bool
28 {
29 return empty($this->error);
30 }
31
32 public function error(): ?string
33 {
34 return $this->error;
35 }
36
37 private function update_wp_option($healthy)
38 {
39 if ($healthy) {
40 $now = new \DateTime('now');
41 delete_option(self::REST_LAST_HEALTHY_AT);
42 add_option(self::REST_LAST_HEALTHY_AT, $now->format('c'));
43 } else {
44 delete_option(self::REST_LAST_HEALTHY_AT);
45 }
46 }
47
48 /**
49 * @return string|null Returns a string error message if the health check fails
50 */
51 private function plugin_health_check(): ?string
52 {
53 $active_plugins = get_option('active_plugins');
54
55 if (in_array('disable-wp-rest-api/disable-wp-rest-api.php', $active_plugins)) {
56 return __('The "Disable WP REST API" plugin needs to be deactivated because Independent Analytics uses the REST API to record visits.', 'iawp');
57 }
58 if (in_array('all-in-one-wp-security-and-firewall/wp-security.php', $active_plugins)) {
59 $settings = get_option('aio_wp_security_configs', []);
60 if (array_key_exists('aiowps_disallow_unauthorized_rest_requests', $settings)) {
61 if ($settings['aiowps_disallow_unauthorized_rest_requests'] == 1) {
62 return __('The "All In WP Security" plugin is blocking REST API requests, which Independent Analytics needs to record views. Please disable this setting via the WP Security > Miscellaneous menu.', 'iawp');
63 }
64 }
65 }
66 if (in_array('disable-json-api/disable-json-api.php', $active_plugins)) {
67 $settings = get_option('disable_rest_api_options', []);
68 if (array_key_exists('roles', $settings)) {
69 if ($settings['roles']['none']['default_allow'] == false) {
70 if ($settings['roles']['none']['allow_list']['/iawp/search'] == false) {
71 return __('The "Disable REST API" plugin is blocking REST API requests for unauthenticated users, which Independent Analytics needs to record views. Please enable the /iawp/search route, so Independent Analytics can track your visitors.', 'iawp');
72 }
73 }
74 }
75 }
76 if (in_array('disable-xml-rpc-api/disable-xml-rpc-api.php', $active_plugins)) {
77 $settings = get_option('dsxmlrpc-settings');
78 if (array_key_exists('json-rest-api', $settings)) {
79 if ($settings['json-rest-api'] == 1) {
80 return __('The "Disable XML-RPC-API" plugin is blocking REST API requests, which Independent Analytics needs to record views. Please visit the Security Settings menu and turn off the "Disable JSON REST API" option, so Independent Analytics can track your visitors.', 'iawp');
81 }
82 }
83 }
84 if (in_array('wpo-tweaks/wordpress-wpo-tweaks.php', $active_plugins)) {
85 return __('The "WPO Tweaks & Optimizations" plugin needs to be deactivated because it is disabling the REST API, which Independent Analytics uses to record visits.', 'iawp');
86 }
87 if (in_array('all-in-one-intranet/basic_all_in_one_intranet.php', $active_plugins)) {
88 return __('The "All-In-One Intranet" plugin needs to be deactivated because it is disabling the REST API, which Independent Analytics uses to record visits. You may want to try the "My Private Site" plugin instead.', 'iawp');
89 }
90
91 return null;
92 }
93
94 private function rest_health_check(): ?string
95 {
96 $url = get_rest_url() . 'iawp/search';
97 $request = wp_remote_post($url);
98
99 if (is_wp_error($request) || wp_remote_retrieve_response_code($request) !== 200 || wp_remote_retrieve_header($request, 'X-IAWP') !== 'IAWP') {
100 return __('It looks like you\'re blocking REST API requests with a plugin or code snippet. The REST API needs to be enabled because this is how Independent Analytics records visits.', 'iawp');
101 }
102
103 return null;
104 }
105
106 private function should_run_rest_health_check(): bool
107 {
108 try {
109 $last_healthy_at = get_option(self::REST_LAST_HEALTHY_AT, date('c', 0));
110 $last_healthy_at = new \DateTime($last_healthy_at);
111 } catch (\Exception $e) {
112 return true;
113 }
114
115 $now = new \DateTime();
116 $diff = $last_healthy_at->diff($now);
117 $hours_ago = $diff->h + ($diff->days * 24);
118
119 return $hours_ago >= 1;
120 }
121 }
122