PluginProbe
SpinupWP / trunk
SpinupWP vtrunk
trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2 1.3 1.4 1.4.1 1.4.2 1.5 1.5.1 1.6 1.7 1.7.1 1.8.0 1.9.0 1.9.1
spinupwp / src / SiteHealth.php

SiteHealth.php in SpinupWP trunk, at src/SiteHealth.php

100 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpinupWp;
4
5 class SiteHealth {
6
7 /**
8 * Init
9 */
10 public function init() {
11 add_filter( 'site_status_tests', array( $this, 'filter_site_health_checks' ) );
12 add_filter( 'site_status_page_cache_supported_cache_headers', array( $this, 'filter_page_cache_headers' ) );
13 }
14
15 /**
16 * Add SpinupWP specific tests to the site health screen.
17 *
18 * @param array $tests
19 *
20 * @return array
21 */
22 public function filter_site_health_checks( $tests ) {
23 $tests['direct']['debug_enabled'] = array(
24 'label' => __( 'Debugging enabled' ),
25 'test' => array( $this, 'test_debug_mode' )
26 );
27
28 return $tests;
29 }
30
31 /**
32 * Test if debug information is enabled.
33 *
34 * Copied from `WP_Site_Health::get_test_is_in_debug_mode` but removed
35 * warning about `WP_DEBUG_LOG` constant because SpinupWP denies access
36 * to all *.log files.
37 *
38 * @return array The test results.
39 */
40 public function test_debug_mode() {
41 $result = array(
42 'label' => __( 'Your site is not set to output debug information' ),
43 'status' => 'good',
44 'badge' => array(
45 'label' => __( 'Security' ),
46 'color' => 'blue',
47 ),
48 'description' => sprintf(
49 '<p>%s</p>',
50 __( 'Debug mode is often enabled to gather more details about an error or site failure, but may contain sensitive information which should not be available on a publicly available website.' )
51 ),
52 'actions' => sprintf(
53 '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
54 /* translators: Documentation explaining debugging in WordPress. */
55 esc_url( __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) ),
56 __( 'Read about debugging in WordPress.' ),
57 /* translators: accessibility text */
58 __( '(opens in a new tab)' )
59 ),
60 'test' => 'is_in_debug_mode',
61 );
62
63 if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) {
64 $result['label'] = __( 'Your site is set to display errors to site visitors' );
65
66 $result['status'] = 'critical';
67
68 $result['description'] .= sprintf(
69 '<p>%s</p>',
70 sprintf(
71 /* translators: 1: WP_DEBUG_DISPLAY, 2: WP_DEBUG */
72 __( 'The value, %1$s, has either been enabled by %2$s or added to your configuration file. This will make errors display on the front end of your site.' ),
73 '<code>WP_DEBUG_DISPLAY</code>',
74 '<code>WP_DEBUG</code>'
75 )
76 );
77 }
78
79 return $result;
80 }
81
82 /**
83 * Filters the list of cache headers supported by core.
84 *
85 * @param array $cache_headers
86 *
87 * @return array
88 */
89 public function filter_page_cache_headers( $cache_headers ) {
90 $cache_headers['fastcgi-cache'] = static function ( $header_value ) {
91 return in_array( strtolower( $header_value ), array(
92 'hit',
93 'miss',
94 'bypass',
95 ), true );
96 };
97
98 return $cache_headers;
99 }
100 }