Skip to content

Commit e2f463d

Browse files
authored
Merge pull request #38 from Automattic/fix/ignore-for-jetpack-requests
Don't send 503 on requests coming from Jetpack
2 parents a6646c2 + 2f7e7cf commit e2f463d

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

maintenance-mode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Shut down your site for a little while and do some maintenance on it!
66
* Author: Automattic / WordPress.com VIP
77
* Author URI: https://vip.wordpress.com
8-
* Version: 0.2.1
8+
* Version: 0.2.2
99
* License: GPLv2
1010
* Text Domain: maintenance-mode
1111
* Domain Path: /languages

readme.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: wpcomvip, automattic, benoitchantre, emrikol, philipjohn
33
Tags: maintenance-mode maintenance
44
Requires at least: 4.6
5-
Tested up to: 5.0
6-
Stable tag: 0.2.1
5+
Tested up to: 5.2.2
6+
Stable tag: 0.2.2
77
License: GPLv2 or later
88
License URI: https://www.gnu.org/licenses/gpl-2.0.html
99

@@ -25,6 +25,9 @@ Usage:
2525

2626
== Changelog ==
2727

28+
= 0.2.2 =
29+
* Stop returning a 503 to Jetpack requests to prevent broken connection verification
30+
2831
= 0.2.1 =
2932
* Stop returning a 503 to Nagios on WPCom and VipGo to prevent alerting as a server error
3033

template-maintenance-mode.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
<head>
44
<meta charset="<?php bloginfo( 'charset' ); ?>">
55
<?php wp_head(); // allow for remote-login on mapped domains ?>
6+
<style>
7+
.mm-wrapper {
8+
display: flex;
9+
width: 100vw;
10+
height: 100vh;
11+
justify-content: center;
12+
align-items: center;
13+
flex-flow: column wrap;
14+
font-size: 2rem;
15+
}
16+
</style>
617
</head>
718
<body>
8-
<h1><?php esc_html_e( 'Howdy!', 'maintenance-mode' ); ?></h1>
9-
<p><?php esc_html_e( 'We\'re just freshening things up a bit; back in a few!', 'maintenance-mode' ); ?></p>
19+
<div class="mm-wrapper">
20+
<h1><?php esc_html_e( 'Howdy!', 'maintenance-mode' ); ?></h1>
21+
<p><?php esc_html_e( 'We\'re just freshening things up a bit; back in a few!', 'maintenance-mode' ); ?></p>
22+
</div>
1023
<?php wp_footer(); ?>
1124
</body>
1225
</html>

vipgo-helper.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
<?php
22

33
/**
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.
55
*
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.
99
*
10-
* @return bool Should maintenance_mode set a 503 header
10+
* @return bool Should Maintenance Mode set a 503 header
1111
*/
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 {
1313
$user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
1414

1515
// The request comes from Nagios so deny the 503 header being set.
1616
// Desktop checks use something like `check_http/v2.2.1 (nagios-plugins 2.2.1)`.
1717
// 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() ) ) {
1920
return false;
2021
}
2122

2223
return $should_set_503;
2324
}
2425

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

Comments
 (0)