|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * Prevent the maintenance_mode plugin returning a 503 HTTP status to Nagios. |
| 4 | + * Prevent the Maintenance Mode plugin returning a 503 HTTP status to Nagios and Jetpack. |
5 | 5 | * |
6 | | - * Maintenance_mode sets a 503 header on page requests if maintenance_mode is enabled and this leads to Nagios |
7 | | - * reporting lots of server errors for sites that are just in maintenance_mode. This function sets the filter |
8 | | - * response that maintenance_mode uses to determine if it shoudl set teh 503 status header or not. |
| 6 | + * Maintenance Mode sets a 503 header on page requests if Maintenance Mode is enabled and this leads to Nagios |
| 7 | + * reporting lots of server errors and Jetpack not being able to verify connection status for sites that are just in maintenance_mode. This function sets the filter |
| 8 | + * response that Maintenance Mode uses to determine if it should set the 503 status header or not. |
9 | 9 | * |
10 | | - * @return bool Should maintenance_mode set a 503 header |
| 10 | + * @return bool Should Maintenance Mode set a 503 header |
11 | 11 | */ |
12 | | -function wpcom_vip_maintenance_mode_do_not_respond_503_for_nagios( $should_set_503 ) { |
| 12 | +function wpcom_vip_maintenance_mode_do_not_respond_503_for_services( $should_set_503 ): bool { |
13 | 13 | $user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
14 | 14 |
|
15 | 15 | // The request comes from Nagios so deny the 503 header being set. |
16 | 16 | // Desktop checks use something like `check_http/v2.2.1 (nagios-plugins 2.2.1)`. |
17 | 17 | // Mobile checks use `iphone`. |
18 | | - if ( false !== strpos( $user_agent, 'check_http' ) || 'iphone' === $user_agent ) { |
| 18 | + // Utilize helper function vip_is_jetpack_request if available |
| 19 | + if ( false !== strpos( $user_agent, 'check_http' ) || 'iphone' === $user_agent || ( function_exists( 'vip_is_jetpack_request' ) && vip_is_jetpack_request() ) ) { |
19 | 20 | return false; |
20 | 21 | } |
21 | 22 |
|
22 | 23 | return $should_set_503; |
23 | 24 | } |
24 | 25 |
|
25 | | -add_filter( 'vip_maintenance_mode_respond_503', 'wpcom_vip_maintenance_mode_do_not_respond_503_for_nagios', 30 ); |
| 26 | +add_filter( 'vip_maintenance_mode_respond_503', 'wpcom_vip_maintenance_mode_do_not_respond_503_for_services', 30 ); |
0 commit comments