PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.5.1
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.5.1
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
nitropack-sdk 5 years ago view 5 years ago advanced-cache.php 5 years ago cf-helper.php 5 years ago constants.php 5 years ago diagnostics.php 5 years ago functions.php 5 years ago integrations.php 5 years ago main.php 5 years ago readme.txt 5 years ago uninstall.php 6 years ago wp-cli.php 5 years ago
diagnostics.php
172 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_get_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 $matchResult = 'An empty SiteID was returned from site config.';
33 }
34 return $matchResult;
35 } catch (\Exception $e) {
36 return $e->getMessage();
37 }
38 }
39
40 function npdiag_get_general_info() {
41 global $wp_version;
42 if (null !== $nitro = get_nitropack_sdk()) {
43 $probe_result = "OK";
44 try {
45 $nitro->fetchConfig();
46 } catch (\Exception $e) {
47 $probe_result = 'Error: ' . $e->getMessage();
48 }
49 } else {
50 $probe_result = 'Error: Cannot get SDK instance';
51 }
52 $info = array(
53 'Nitro_WP_version' => !empty($wp_version) ? $wp_version : get_bloginfo('version'),
54 'Nitro_Version' => defined('NITROPACK_VERSION') ? NITROPACK_VERSION : 'Undefined',
55 'Nitro_API_Connection' => $probe_result,
56 'Nitro_SDK_Version' => defined('NitroPack\SDK\Nitropack::VERSION') ? NitroPack\SDK\Nitropack::VERSION : 'Undefined',
57 'Nitro_WP_Cache' => defined('WP_CACHE') ? (WP_CACHE ? 'OK for drop-in' : 'Turned off') : 'Undefined',
58 'Advanced_Cache_Version' => defined('NITROPACK_ADVANCED_CACHE_VERSION') ? NITROPACK_ADVANCED_CACHE_VERSION : 'Undefined',
59 'Nitro_Absolute_Path' => defined('ABSPATH') ? ABSPATH : 'Undefined',
60 'Nitro_Plugin_Direcotry' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__),
61 'Nitro_Data_Directory' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : 'Undefined',
62 'Nitro_Config_File' => defined('NITROPACK_CONFIG_FILE') ? NITROPACK_CONFIG_FILE : 'Undefined',
63 'Nitro_Webhooks' => $nitro ? npdiag_helper_compare_webhooks($nitro) : 'Error: Cannot get SDK instance'
64 );
65
66 if (defined("NITROPACK_VERSION") && defined("NITROPACK_ADVANCED_CACHE_VERSION") && NITROPACK_VERSION == NITROPACK_ADVANCED_CACHE_VERSION && nitropack_is_dropin_cache_allowed()) {
67 $info['Nitro_Cache_Method'] = 'drop-in';
68 } elseif ( defined('EZOIC_INTEGRATION_VERSION') ) {
69 $info['Nitro_Cache_Method'] = 'plugin-ezoic';
70 } else {
71 $info['Nitro_Cache_Method'] = 'plugin';
72 }
73
74 return $info;
75 }
76
77 function npdiag_get_active_plugins() {
78 if (is_admin()) {
79 $info = array();
80 $raw_installed_list = get_plugins();
81 $raw_active_list = get_option('active_plugins');
82 foreach ($raw_installed_list as $pkey => $pval) {
83 if ( in_array($pkey, $raw_active_list) ) {
84 $info[$pval['Name']] = $pval['Version'];
85 }
86 }
87 }
88
89 return $info;
90 }
91
92 function npdiag_get_user_config() {
93 if (defined('NITROPACK_CONFIG_FILE')) {
94 if (file_exists(NITROPACK_CONFIG_FILE)) {
95 $info = json_decode(file_get_contents(NITROPACK_CONFIG_FILE));
96 if (!$info) {
97 $info = 'Config found, but unable to get contents.';
98 }
99 } else {
100 $info = 'Config file not found.';
101 }
102 } else {
103 $info = 'Config file constant is not defined.';
104 }
105
106 return $info;
107 }
108
109 function npdiag_get_dir_info() {
110 $siteConfig = nitropack_get_site_config();
111 $siteID = !empty($siteConfig['siteId']) ? $siteConfig['siteId'] : get_option('nitropack-siteId');
112 // DoI = Directories of Interest
113 $DoI = array(
114 'WP_Content_Dir_Writable' => defined('WP_CONTENT_DIRR') ? WP_CONTENT_DIR : (defined('ABSPATH') ? ABSPATH . '/wp-content' : 'Undefined'),
115 'Nitro_Data_Dir_Writable' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack',
116 'Nitro_siteID_Dir_Writable' => npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack/' . $siteID,
117 'Nitro_Plugin_Dir_Writable' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__)
118 );
119
120 $info = array();
121 foreach ($DoI as $doi_dir => $dpath) {
122 if (is_dir($dpath)) {
123 $info[$doi_dir] = is_writeable($dpath) ? true : false;
124 } else if (is_file($dpath)) {
125 $info[$doi_dir] = "$dpath is a file not a directory";
126 } else {
127 $info[$doi_dir] = 'Directory not found';
128 }
129 }
130
131 return $info;
132 }
133
134 function npdiag_get_third_party_cache() {
135 $info = "Get info about other caching solutions' residual cache. Placeholder for now.";
136 return $info;
137 }
138
139 function npdiag_get_conflicting_plugins() {
140 $info = nitropack_get_conflicting_plugins();
141 if ( !empty($info) ) {
142 return $info;
143 } else {
144 return $info = 'None detected';
145 }
146 }
147
148 function nitropack_generate_report() {
149 global $np_diag_functions;
150 try {
151 $ar = !empty($_POST["toggled"]) ? $_POST["toggled"] : NULL;
152 if ( $ar !== NULL) {
153 $diag_data = array('report-time-stamp' => date("Y-m-d H:i:s"));
154 foreach ($ar as $func_name => $func_allowed) {
155 if ((boolean)$func_allowed) {
156 $diag_data[$func_name] = call_user_func($np_diag_functions[$func_name]);
157 }
158 }
159 $str = json_encode($diag_data, JSON_PRETTY_PRINT);
160 $filename = 'nitropack_diag_file.txt';
161 header('Content-Disposition: attachment; filename="'.$filename.'"');
162 header("Content-Type: text/plain");
163 header("Content-Length: " . strlen($str));
164 echo $str;
165 exit;
166 }
167 } catch (\Exception $e) {
168 //exception handling here
169 }
170
171 }
172