PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.20.0
Independent Analytics – WordPress Analytics Plugin v1.20.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 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
AJAX 3 years ago Migrations 3 years ago Models 3 years ago Queries 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 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 REST_API.php 3 years ago Real_Time.php 3 years ago Settings.php 3 years ago Track_Resource_Changes.php 3 years ago View_Counter.php 3 years ago WP_Option_Cache_Bust.php 3 years ago WooCommerce_Order.php 3 years ago
Health_Check.php
112 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 class Health_Check
6 {
7 const REST_LAST_HEALTHY_AT = 'iawp_rest_last_healthy_at';
8 private $error;
9 public function __construct()
10 {
11 $this->error = $this->plugin_health_check();
12 // Only run the rest check if the plugin checks have passed
13 if (!isset($this->error) && $this->should_run_rest_health_check()) {
14 $rest_error = $this->rest_health_check();
15 if (isset($rest_error)) {
16 $this->error = $rest_error;
17 $this->update_wp_option(\false);
18 } else {
19 $this->update_wp_option(\true);
20 }
21 }
22 }
23 public function healthy() : bool
24 {
25 return empty($this->error);
26 }
27 public function error() : ?string
28 {
29 return $this->error;
30 }
31 private function update_wp_option($healthy)
32 {
33 if ($healthy) {
34 $now = new \DateTime('now');
35 \delete_option(self::REST_LAST_HEALTHY_AT);
36 \add_option(self::REST_LAST_HEALTHY_AT, $now->format('c'));
37 } else {
38 \delete_option(self::REST_LAST_HEALTHY_AT);
39 }
40 }
41 /**
42 * @return string|null Returns a string error message if the health check fails
43 */
44 private function plugin_health_check() : ?string
45 {
46 $active_plugins = \get_option('active_plugins');
47 if (\in_array('disable-wp-rest-api/disable-wp-rest-api.php', $active_plugins)) {
48 return \__('The "Disable WP REST API" plugin needs to be deactivated because Independent Analytics uses the REST API to record visits.', 'iawp');
49 }
50 if (\in_array('all-in-one-wp-security-and-firewall/wp-security.php', $active_plugins)) {
51 $settings = \get_option('aio_wp_security_configs', []);
52 if (\array_key_exists('aiowps_disallow_unauthorized_rest_requests', $settings)) {
53 if ($settings['aiowps_disallow_unauthorized_rest_requests'] == 1) {
54 return \__('The "All In One 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');
55 }
56 }
57 }
58 if (\in_array('disable-json-api/disable-json-api.php', $active_plugins)) {
59 $settings = \get_option('disable_rest_api_options', []);
60 if (\array_key_exists('roles', $settings)) {
61 if ($settings['roles']['none']['default_allow'] == \false) {
62 if ($settings['roles']['none']['allow_list']['/iawp/search'] == \false) {
63 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');
64 }
65 }
66 }
67 }
68 if (\in_array('disable-xml-rpc-api/disable-xml-rpc-api.php', $active_plugins)) {
69 $settings = \get_option('dsxmlrpc-settings');
70 if (\array_key_exists('json-rest-api', $settings)) {
71 if ($settings['json-rest-api'] == 1) {
72 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');
73 }
74 }
75 }
76 if (\in_array('wpo-tweaks/wordpress-wpo-tweaks.php', $active_plugins)) {
77 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');
78 }
79 if (\in_array('all-in-one-intranet/basic_all_in_one_intranet.php', $active_plugins)) {
80 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');
81 }
82 return null;
83 }
84 private function rest_health_check() : ?string
85 {
86 $url = \get_rest_url() . 'iawp/search';
87 $request = \wp_remote_post($url);
88 // Skip the health check if the REST API has been put behind authentication
89 // This would only impact people who added custom code to block REST access and have a password-protected site
90 if (\wp_remote_retrieve_response_code($request) === 401) {
91 return null;
92 }
93 if (\is_wp_error($request) || \wp_remote_retrieve_response_code($request) !== 200 || \wp_remote_retrieve_header($request, 'X-IAWP') !== 'IAWP') {
94 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');
95 }
96 return null;
97 }
98 private function should_run_rest_health_check() : bool
99 {
100 try {
101 $last_healthy_at = \get_option(self::REST_LAST_HEALTHY_AT, \date('c', 0));
102 $last_healthy_at = new \DateTime($last_healthy_at);
103 } catch (\Exception $e) {
104 return \true;
105 }
106 $now = new \DateTime();
107 $diff = $last_healthy_at->diff($now);
108 $hours_ago = $diff->h + $diff->days * 24;
109 return $hours_ago >= 1;
110 }
111 }
112