| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -/* | |
| 2 | +/** | |
| 3 | 3 | +=====================================================================+ |
| 4 | 4 | | ____ _ ____ __ _ _ | |
| 5 | 5 | | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ | |
| 6 | 6 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| @@ -6,33 +6,38 @@ | ||
| 6 | 6 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| 7 | 7 | | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | | |
| 8 | 8 | | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| | |
| 9 | 9 | | | |
| 10 | - | (c) Jerome Bruandet ~ https://code-profiler.com/ | | |
| 11 | - +=====================================================================+ | |
| 10 | + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ | | |
| 11 | + +=====================================================================+ 2024-08-14 | |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (! defined('ABSPATH') ) { die('Forbidden'); } | |
| 14 | +if (! defined('ABSPATH') ) { | |
| 15 | + die('Forbidden'); | |
| 16 | +} | |
| 15 | 17 | |
| 16 | 18 | // ===================================================================== |
| 17 | 19 | |
| 18 | 20 | class CP_Troubleshooter { |
| 19 | 21 | |
| 20 | - /******************************************************************** | |
| 22 | + /** | |
| 21 | 23 | * Array to handle all results |
| 22 | 24 | */ |
| 23 | 25 | private $buffer = []; |
| 24 | 26 | |
| 25 | - /******************************************************************** | |
| 27 | + /** | |
| 26 | 28 | * Initialize. |
| 27 | 29 | */ |
| 28 | 30 | public function __construct() { |
| 29 | 31 | |
| 30 | 32 | $this->get_system_info('sysinfo'); |
| 33 | + $this->test_admin_ajax('admin-ajax'); | |
| 31 | 34 | $this->cp_info('code-profiler'); |
| 32 | 35 | $this->function_exists('code-profiler'); |
| 33 | 36 | $this->check_wpdb('wpdb'); |
| 37 | + $this->check_cache('cache'); | |
| 34 | 38 | $this->check_proxy('proxy'); |
| 39 | + $this->is_multisite('multisite'); | |
| 35 | 40 | $this->get_all_plugins('plugins'); |
| 36 | 41 | $this->get_theme('themes'); |
| 37 | 42 | $this->get_cp_config(); |
| 38 | 43 | |
| @@ -38,9 +43,9 @@ | ||
| 38 | 43 | |
| 39 | 44 | echo esc_textarea( print_r( $this->buffer, true ) ); |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | - /******************************************************************** | |
| 47 | + /** | |
| 43 | 48 | * Retrieve system info: |
| 44 | 49 | * * PHP version |
| 45 | 50 | * * PHP SAPI |
| 46 | 51 | * * HTTP server |
| @@ -52,8 +57,14 @@ | ||
| 52 | 57 | private function get_system_info( $key ) { |
| 53 | 58 | |
| 54 | 59 | $this->buffer[ $key ]['OS'] = php_uname(); |
| 55 | 60 | |
| 61 | + if (! empty( $_SERVER['SERVER_NAME'] ) ) { | |
| 62 | + $this->buffer[ $key ]['SERVER_NAME'] = $_SERVER['SERVER_NAME']; | |
| 63 | + } else { | |
| 64 | + $this->buffer[ $key ]['SERVER_NAME'] = 'N/A'; | |
| 65 | + } | |
| 66 | + | |
| 56 | 67 | if (! empty( $_SERVER['SERVER_SOFTWARE'] ) ) { |
| 57 | 68 | $this->buffer[ $key ]['HTTP server'] = $_SERVER['SERVER_SOFTWARE']; |
| 58 | 69 | } else { |
| 59 | 70 | $this->buffer[ $key ]['HTTP server'] = 'N/A'; |
| @@ -81,9 +92,9 @@ | ||
| 81 | 92 | if (! empty( $tmp ) ) { |
| 82 | 93 | if ( is_writable( $tmp ) ) { |
| 83 | 94 | $tmp .= ' (writable)'; |
| 84 | 95 | } else { |
| 85 | - $tmp .= ' (not writable!)'; | |
| 96 | + $tmp .= ' (not writable!)' .' ⚠️'; | |
| 86 | 97 | } |
| 87 | 98 | } |
| 88 | 99 | $tmp = $this->shorten_path( $tmp ); |
| 89 | 100 | $this->buffer[ $key ]['Temp directory'] = $tmp; |
| @@ -129,11 +140,41 @@ | ||
| 129 | 140 | $wp_debug = $this->shorten_path( $wp_debug ) ." (". number_format( $filesize ) ." bytes)"; |
| 130 | 141 | } |
| 131 | 142 | $this->buffer[ $key ]['WordPress']['WP_DEBUG_LOG'] = $wp_debug; |
| 132 | 143 | |
| 144 | + /** | |
| 145 | + * WPMU plugins directory. | |
| 146 | + */ | |
| 147 | + $this->buffer[ $key ]['WordPress']['WPMU_PLUGIN_DIR']['DIR'] = | |
| 148 | + $this->shorten_path( WPMU_PLUGIN_DIR ); | |
| 149 | + $this->buffer[ $key ]['WordPress']['WPMU_PLUGIN_DIR']['writable'] = | |
| 150 | + is_writable( WPMU_PLUGIN_DIR ); | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * SAVEQUERIES: make sure it is not set to false. | |
| 154 | + */ | |
| 155 | + if ( defined('SAVEQUERIES') ) { | |
| 156 | + if ( SAVEQUERIES === false ) { | |
| 157 | + $this->buffer[ $key ]['WordPress']['SAVEQUERIES'] = 'FALSE' .' ⚠️'; | |
| 158 | + } else { | |
| 159 | + $this->buffer[ $key ]['WordPress']['SAVEQUERIES'] = SAVEQUERIES; | |
| 160 | + } | |
| 161 | + } else { | |
| 162 | + $this->buffer[ $key ]['WordPress']['SAVEQUERIES'] = 'N/A'; | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * xdebug. | |
| 167 | + */ | |
| 168 | + if ( extension_loaded('xdebug') ) { | |
| 169 | + $this->buffer[ $key ]['Xdebug'] = esc_html__('Extension is loaded', 'code-profiler') .' ⚠️'; | |
| 170 | + } else { | |
| 171 | + $this->buffer[ $key ]['Xdebug'] = '0'; | |
| 172 | + } | |
| 133 | 173 | } |
| 134 | 174 | |
| 135 | - /******************************************************************** | |
| 175 | + | |
| 176 | + /** | |
| 136 | 177 | * Verify if some important PHP functions are available. |
| 137 | 178 | */ |
| 138 | 179 | private function function_exists( $key ) { |
| 139 | 180 | |
| @@ -141,18 +182,26 @@ | ||
| 141 | 182 | 'register_shutdown_function' => 'shutdown', |
| 142 | 183 | 'register_tick_function' => 'tick', |
| 143 | 184 | 'stream_wrapper_unregister' => 'unregister', |
| 144 | 185 | 'stream_wrapper_register' => 'register', |
| 145 | - 'stream_wrapper_restore' => 'restore' | |
| 186 | + 'stream_wrapper_restore' => 'restore', | |
| 187 | + 'hrtime' => 'hrtime' | |
| 146 | 188 | ]; |
| 147 | 189 | |
| 148 | 190 | foreach ( $required_functions as $function => $value ) { |
| 149 | - $this->buffer[ $key ][ $value ] = function_exists( $function ); | |
| 191 | + $this->buffer[ $key ]['function'][ $value ] = function_exists( $function ); | |
| 150 | 192 | } |
| 193 | + | |
| 194 | + $required_methods = [ | |
| 195 | + 'PhpToken' => 'tokenize' | |
| 196 | + ]; | |
| 197 | + foreach ( $required_methods as $class => $value ) { | |
| 198 | + $this->buffer[ $key ]['method'][ $value ] = method_exists( $class, $value ); | |
| 199 | + } | |
| 151 | 200 | } |
| 152 | 201 | |
| 153 | 202 | |
| 154 | - /******************************************************************** | |
| 203 | + /** | |
| 155 | 204 | * Return the version and type (free/pro) of Code Profiler. |
| 156 | 205 | */ |
| 157 | 206 | private function cp_info( $key ) { |
| 158 | 207 | |
| @@ -178,9 +227,9 @@ | ||
| 178 | 227 | $this->buffer[ $key ]['data_dir']['writable'] = is_writable( $dir ); |
| 179 | 228 | } |
| 180 | 229 | |
| 181 | 230 | |
| 182 | - /******************************************************************** | |
| 231 | + /** | |
| 183 | 232 | * Check if there are subclasses of the wpdb class and |
| 184 | 233 | * look for wp-content/db.php |
| 185 | 234 | */ |
| 186 | 235 | function check_wpdb( $key ) { |
| @@ -196,18 +245,21 @@ | ||
| 196 | 245 | $this->buffer[ $key ][ $db_php ] = file_exists( WP_CONTENT_DIR .'/db.php'); |
| 197 | 246 | } |
| 198 | 247 | |
| 199 | 248 | |
| 200 | - /******************************************************************** | |
| 249 | + /** | |
| 201 | 250 | * Check for advanced cache |
| 202 | 251 | */ |
| 203 | 252 | private function check_cache( $key ) { |
| 204 | 253 | |
| 205 | - $this->buffer[ $key ]['cache'] = defined('WP_CACHE') && file_exists(WP_CONTENT_DIR . '/advanced-cache.php'); | |
| 254 | + $this->buffer[ $key ] = []; | |
| 255 | + if ( defined('WP_CACHE') && file_exists( WP_CONTENT_DIR . '/advanced-cache.php') ) { | |
| 256 | + $this->buffer[ $key ][ $this->shorten_path( WP_CONTENT_DIR . '/advanced-cache.php') ] = 1; | |
| 257 | + } | |
| 206 | 258 | } |
| 207 | 259 | |
| 208 | 260 | |
| 209 | - /******************************************************************** | |
| 261 | + /** | |
| 210 | 262 | * Check for reverse proxy or CDN |
| 211 | 263 | */ |
| 212 | 264 | private function check_proxy( $key ) { |
| 213 | 265 | |
| @@ -226,9 +278,24 @@ | ||
| 226 | 278 | |
| 227 | 279 | } |
| 228 | 280 | |
| 229 | 281 | |
| 230 | - /******************************************************************** | |
| 282 | + /** | |
| 283 | + * Check if that is a multisite installation. | |
| 284 | + */ | |
| 285 | + private function is_multisite( $key ) { | |
| 286 | + | |
| 287 | + if ( is_multisite() ) { | |
| 288 | + global $current_blog; | |
| 289 | + $this->buffer[ $key ] = "site: {$current_blog->site_id}, blog: {$current_blog->blog_id}"; | |
| 290 | + return; | |
| 291 | + } | |
| 292 | + | |
| 293 | + $this->buffer[ $key ] = 0; | |
| 294 | + } | |
| 295 | + | |
| 296 | + | |
| 297 | + /** | |
| 231 | 298 | * Retrieve the list of all plugins and sort them |
| 232 | 299 | * (active or disabled). |
| 233 | 300 | */ |
| 234 | 301 | private function get_all_plugins( $key ) { |
| @@ -275,9 +342,9 @@ | ||
| 275 | 342 | |
| 276 | 343 | } |
| 277 | 344 | |
| 278 | 345 | |
| 279 | - /******************************************************************** | |
| 346 | + /** | |
| 280 | 347 | * Retrieve the active theme. |
| 281 | 348 | */ |
| 282 | 349 | private function get_theme( $key ) { |
| 283 | 350 | |
| @@ -299,9 +366,9 @@ | ||
| 299 | 366 | } |
| 300 | 367 | } |
| 301 | 368 | |
| 302 | 369 | |
| 303 | - /******************************************************************** | |
| 370 | + /** | |
| 304 | 371 | * Retrieve Code Profiler's configuration |
| 305 | 372 | */ |
| 306 | 373 | private function get_cp_config() { |
| 307 | 374 | |
| @@ -308,9 +375,8 @@ | ||
| 308 | 375 | $cp_options = get_option('code-profiler'); |
| 309 | 376 | |
| 310 | 377 | $list = [ |
| 311 | 378 | 'hide_empty_value', |
| 312 | - 'warn_composer', | |
| 313 | 379 | 'enable_wpcli', |
| 314 | 380 | 'disable_wpcron', |
| 315 | 381 | // 'disable_db-php', |
| 316 | 382 | 'http_response', |
| @@ -315,9 +381,10 @@ | ||
| 315 | 381 | // 'disable_db-php', |
| 316 | 382 | 'http_response', |
| 317 | 383 | // 'backtrace_limit', |
| 318 | 384 | 'accuracy', |
| 319 | - 'buffer' | |
| 385 | + 'buffer', | |
| 386 | + 'exclusions' | |
| 320 | 387 | ]; |
| 321 | 388 | foreach( $list as $element ) { |
| 322 | 389 | $this->buffer['options'][ $element ] = isset( $cp_options[ $element ] )? $cp_options[ $element ]:0; |
| 323 | 390 | } |
| @@ -322,14 +389,42 @@ | ||
| 322 | 389 | $this->buffer['options'][ $element ] = isset( $cp_options[ $element ] )? $cp_options[ $element ]:0; |
| 323 | 390 | } |
| 324 | 391 | } |
| 325 | 392 | |
| 326 | - /******************************************************************** | |
| 393 | + /** | |
| 327 | 394 | * Remove the ABSPATH from a path |
| 328 | 395 | */ |
| 329 | 396 | private function shorten_path( $path ) { |
| 330 | 397 | |
| 331 | 398 | return str_replace( ABSPATH, '', $path ); |
| 399 | + } | |
| 400 | + | |
| 401 | + | |
| 402 | + /** | |
| 403 | + * Test if admin-ajax is accessible. | |
| 404 | + */ | |
| 405 | + private function test_admin_ajax( $key ) { | |
| 406 | + | |
| 407 | + $headers = [ | |
| 408 | + // Devs must be allowed to use it on localhost over TLS too | |
| 409 | + 'sslverify' => apply_filters('https_local_ssl_verify', false ) | |
| 410 | + ]; | |
| 411 | + $res = wp_safe_remote_get( admin_url('admin-ajax.php?action=generate-password'), $headers ); | |
| 412 | + | |
| 413 | + /* Translators: Error message */ | |
| 414 | + $error = __('Error: %s', 'code-profiler'); | |
| 415 | + | |
| 416 | + // Connection error | |
| 417 | + if ( is_wp_error( $res ) ) { | |
| 418 | + $msg = sprintf( $error, $res->get_error_message() ); | |
| 419 | + | |
| 420 | + } elseif ( $res['response']['code'] != 200 ) { | |
| 421 | + $msg = sprintf( $error, $res['response']['code'] ." ". $res['response']['message'] ); | |
| 422 | + | |
| 423 | + } else { | |
| 424 | + $msg = "OK"; | |
| 425 | + } | |
| 426 | + $this->buffer[ $key ]['access'] = $msg; | |
| 332 | 427 | } |
| 333 | 428 | |
| 334 | 429 | } |
| 335 | 430 | |