PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.5.8
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.5.8
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / diagnostics.php
nitropack Last commit date
classes 4 years ago nitropack-sdk 4 years ago view 4 years ago advanced-cache.php 5 years ago batcache-compat.php 4 years ago cf-helper.php 5 years ago constants.php 4 years ago diagnostics.php 4 years ago functions.php 4 years ago integrations.php 4 years ago main.php 4 years ago readme.txt 4 years ago uninstall.php 4 years ago wp-cli.php 5 years ago
diagnostics.php
184 lines
1 <?php
2
3 defined( 'ABSPATH' ) or die( 'Someone made a boo boo!' );
4
5 if (!function_exists('get_plugins')) {
6 require_once ABSPATH . 'wp-admin/includes/plugin.php';
7 }
8
9 $np_diag_functions = array(
10 'general-info-status' => 'npdiag_get_general_info',
11 'active-plugins-status' => 'npdiag_get_active_plugins',
12 'conflicting-plugins-status' => 'npdiag_get_conflicting_plugins',
13 'user-config-status' => 'npdiag_get_user_config',
14 'dir-info-status' => 'npdiag_get_dir_info',
15 'getexternalcache' => 'npdiag_detect_third_party_cache'
16
17 );
18
19 function npdiag_helper_trailingslashit($string) {
20 return rtrim( $string, '/\\' ) . '/';
21 }
22
23 function npdiag_helper_compare_webhooks($nitro_sdk) {
24 try {
25 $siteConfig = nitropack_get_site_config();
26 if (!empty($siteConfig['siteId'])) {
27 $WHToken = nitropack_generate_webhook_token($siteConfig['siteId']);
28 $constructedWH = new \NitroPack\Url(strtolower(get_home_url())) . '?nitroWebhook=config&token=' . $WHToken;
29 $storedWH = $nitro_sdk->getApi()->getWebhook("config");
30 $matchResult = ($constructedWH == $storedWH) ? 'OK' : 'Warning: Webhooks do not match this site';
31 } else {
32 $debugMsg = empty($_SERVER["HTTP_HOST"]) ? "HTTP_HOST is not defined. " : "";
33 $debugMsg .= empty($_SERVER["REQUEST_URI"]) ? "REQUEST_URI is not defined. " : "";
34 $debugMsg .= empty($debugMsg) ? 'URL used to match config was: ' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : "";
35 $matchResult = 'Site config cannot be found, because ' . $debugMsg;
36 }
37 return $matchResult;
38 } catch (\Exception $e) {
39 return $e->getMessage();
40 }
41 }
42
43 function npdiag_get_general_info() {
44 global $wp_version;
45 if (null !== $nitro = get_nitropack_sdk()) {
46 $probe_result = "OK";
47 try {
48 $nitro->fetchConfig();
49 } catch (\Exception $e) {
50 $probe_result = 'Error: ' . $e->getMessage();
51 }
52 } else {
53 $probe_result = 'Error: Cannot get SDK instance';
54 }
55
56 $third_party_residual_cache = npdiag_detect_third_party_cache();
57
58 $info = array(
59 'Nitro_WP_version' => !empty($wp_version) ? $wp_version : get_bloginfo('version'),
60 'Nitro_Version' => defined('NITROPACK_VERSION') ? NITROPACK_VERSION : 'Undefined',
61 'Nitro_API_Connection' => $probe_result,
62 'Nitro_SDK_Version' => defined('NitroPack\SDK\Nitropack::VERSION') ? NitroPack\SDK\Nitropack::VERSION : 'Undefined',
63 'Nitro_WP_Cache' => defined('WP_CACHE') ? (WP_CACHE ? 'OK for drop-in' : 'Turned off') : 'Undefined',
64 'Advanced_Cache_Version' => defined('NITROPACK_ADVANCED_CACHE_VERSION') ? NITROPACK_ADVANCED_CACHE_VERSION : 'Undefined',
65 'Nitro_Absolute_Path' => defined('ABSPATH') ? ABSPATH : 'Undefined',
66 'Nitro_Plugin_Direcotry' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__),
67 'Nitro_Data_Directory' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : 'Undefined',
68 'Nitro_Config_File' => defined('NITROPACK_CONFIG_FILE') ? NITROPACK_CONFIG_FILE : 'Undefined',
69 'Nitro_Webhooks' => $nitro ? npdiag_helper_compare_webhooks($nitro) : 'Error: Cannot get SDK instance',
70 'Nitro_Connectivity_Requirements' => nitropack_check_func_availability('stream_socket_client') ? 'Yes' : 'Warning: "stream_socket_client" function is disabled.',
71 'Residual_Cache_Found_For' => $third_party_residual_cache,
72 );
73
74 if (defined("NITROPACK_VERSION") && defined("NITROPACK_ADVANCED_CACHE_VERSION") && NITROPACK_VERSION == NITROPACK_ADVANCED_CACHE_VERSION && nitropack_is_dropin_cache_allowed()) {
75 $info['Nitro_Cache_Method'] = 'drop-in';
76 } elseif ( defined('EZOIC_INTEGRATION_VERSION') ) {
77 $info['Nitro_Cache_Method'] = 'plugin-ezoic';
78 } else {
79 $info['Nitro_Cache_Method'] = 'plugin';
80 }
81
82 return $info;
83 }
84
85 function npdiag_get_active_plugins() {
86 if (is_admin()) {
87 $info = array();
88 $raw_installed_list = get_plugins();
89 $raw_active_list = get_option('active_plugins');
90 foreach ($raw_installed_list as $pkey => $pval) {
91 if ( in_array($pkey, $raw_active_list) ) {
92 $info[$pval['Name']] = $pval['Version'];
93 }
94 }
95 }
96
97 return $info;
98 }
99
100 function npdiag_get_user_config() {
101 if (defined('NITROPACK_CONFIG_FILE')) {
102 if (file_exists(NITROPACK_CONFIG_FILE)) {
103 $info = json_decode(file_get_contents(NITROPACK_CONFIG_FILE));
104 if (!$info) {
105 $info = 'Config found, but unable to get contents.';
106 }
107 } else {
108 $info = 'Config file not found.';
109 }
110 } else {
111 $info = 'Config file constant is not defined.';
112 }
113
114 return $info;
115 }
116
117 function npdiag_get_dir_info() {
118 $siteConfig = nitropack_get_site_config();
119 $siteID = !empty($siteConfig['siteId']) ? $siteConfig['siteId'] : get_option('nitropack-siteId');
120 // DoI = Directories of Interest
121 $DoI = array(
122 'WP_Content_Dir_Writable' => defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR : (defined('ABSPATH') ? ABSPATH . '/wp-content' : 'Undefined'),
123 'Nitro_Data_Dir_Writable' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack',
124 'Nitro_siteID_Dir_Writable' => npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack/' . $siteID,
125 'Nitro_Plugin_Dir_Writable' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__)
126 );
127
128 $info = array();
129 foreach ($DoI as $doi_dir => $dpath) {
130 if (is_dir($dpath)) {
131 $info[$doi_dir] = is_writeable($dpath) ? true : false;
132 } else if (is_file($dpath)) {
133 $info[$doi_dir] = "$dpath is a file not a directory";
134 } else {
135 $info[$doi_dir] = 'Directory not found';
136 }
137 }
138
139 return $info;
140 }
141
142 function npdiag_get_conflicting_plugins() {
143 $info = nitropack_get_conflicting_plugins();
144 if ( !empty($info) ) {
145 return $info;
146 } else {
147 return $info = 'None detected';
148 }
149 }
150
151 function npdiag_detect_third_party_cache() {
152 $info = \NitroPack\Integration\Plugin\RC::detectThirdPartyCaches();
153 if ( !empty($info) ) {
154 return $info;
155 } else {
156 return $info = 'Not found';
157 }
158 }
159
160 function nitropack_generate_report() {
161 global $np_diag_functions;
162 try {
163 $ar = !empty($_POST["toggled"]) ? $_POST["toggled"] : NULL;
164 if ($ar !== NULL) {
165 $diag_data = array('report-time-stamp' => date("Y-m-d H:i:s"));
166 foreach ($ar as $func_name => $func_allowed) {
167 if ((boolean)$func_allowed) {
168 $diag_data[$func_name] = call_user_func($np_diag_functions[$func_name]);
169 }
170 }
171 $str = json_encode($diag_data, JSON_PRETTY_PRINT);
172 $filename = 'nitropack_diag_file.txt';
173 header('Content-Disposition: attachment; filename="'.$filename.'"');
174 header("Content-Type: text/plain");
175 header("Content-Length: " . strlen($str));
176 echo $str;
177 exit;
178 }
179 } catch (\Exception $e) {
180 //exception handling here
181 }
182
183 }
184