forked from Automattic/maintenance-mode-wp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpcom-helper.php
26 lines (22 loc) · 1.17 KB
/
wpcom-helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
/**
* Prevent the maintenance_mode plugin returning a 503 HTTP status to Nagios.
*
* Maintenance_mode sets a 503 header on page requests if maintenance_mode is enabled and this leads to Nagios
* reporting lots of server errors for sites that are just in maintenance_mode. This function sets the filter
* response that maintenance_mode uses to determine if it shoudl set teh 503 status header or not.
*
* @return bool Should maintenance_mode set a 503 header
*/
function wpcom_vip_maintenance_mode_do_not_respond_503_for_nagios( $should_set_503 ) {
// phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__HTTP_USER_AGENT__
$user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
// The request comes from Nagios so deny the 503 header being set.
// Desktop checks use something like `check_http/v2.2.1 (nagios-plugins 2.2.1)`.
// Mobile checks use `iphone`.
if ( false !== strpos( $user_agent, 'check_http' ) || 'iphone' === $user_agent ) {
return false;
}
return $should_set_503;
}
add_filter( 'vip_maintenance_mode_respond_503', 'wpcom_vip_maintenance_mode_do_not_respond_503_for_nagios', 30 );