| 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 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Add SpinupWP specific tests to the site health screen. |
| 16 |
* |
| 17 |
* @param array $tests |
| 18 |
* |
| 19 |
* @return array |
| 20 |
*/ |
| 21 |
public function filter_site_health_checks( $tests ) { |
| 22 |
$tests['direct']['debug_enabled'] = array( |
| 23 |
'label' => __( 'Debugging enabled' ), |
| 24 |
'test' => array( $this, 'test_debug_mode' ) |
| 25 |
); |
| 26 |
|
| 27 |
return $tests; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Test if debug information is enabled. |
| 32 |
* |
| 33 |
* Copied from `WP_Site_Health::get_test_is_in_debug_mode` but removed |
| 34 |
* warning about `WP_DEBUG_LOG` constant because SpinupWP denies access |
| 35 |
* to all *.log files. |
| 36 |
* |
| 37 |
* @return array The test results. |
| 38 |
*/ |
| 39 |
public function test_debug_mode() { |
| 40 |
$result = array( |
| 41 |
'label' => __( 'Your site is not set to output debug information' ), |
| 42 |
'status' => 'good', |
| 43 |
'badge' => array( |
| 44 |
'label' => __( 'Security' ), |
| 45 |
'color' => 'blue', |
| 46 |
), |
| 47 |
'description' => sprintf( |
| 48 |
'<p>%s</p>', |
| 49 |
__( '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.' ) |
| 50 |
), |
| 51 |
'actions' => sprintf( |
| 52 |
'<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>', |
| 53 |
/* translators: Documentation explaining debugging in WordPress. */ |
| 54 |
esc_url( __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) ), |
| 55 |
__( 'Read about debugging in WordPress.' ), |
| 56 |
/* translators: accessibility text */ |
| 57 |
__( '(opens in a new tab)' ) |
| 58 |
), |
| 59 |
'test' => 'is_in_debug_mode', |
| 60 |
); |
| 61 |
|
| 62 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) { |
| 63 |
$result['label'] = __( 'Your site is set to display errors to site visitors' ); |
| 64 |
|
| 65 |
$result['status'] = 'critical'; |
| 66 |
|
| 67 |
$result['description'] .= sprintf( |
| 68 |
'<p>%s</p>', |
| 69 |
sprintf( |
| 70 |
/* translators: 1: WP_DEBUG_DISPLAY, 2: WP_DEBUG */ |
| 71 |
__( '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.' ), |
| 72 |
'<code>WP_DEBUG_DISPLAY</code>', |
| 73 |
'<code>WP_DEBUG</code>' |
| 74 |
) |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
return $result; |
| 79 |
} |
| 80 |
} |