Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions maintenance-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,12 @@ function current_user_can_bypass_vip_maintenance_mode() {
return current_user_can( $required_capability );
}

/**
* Redirects visitors and users without edit_posts capability to the maintenance page
*
* Uses the plugin template when there's no template called `template-maintenance-mode.php` in the theme root folder.
*
* @since 0.1.1
*/
function vip_maintenance_mode_template_redirect() {
add_action( 'send_headers', 'vip_maintenance_mode_send_headers', PHP_INT_MAX );

function vip_maintenance_mode_send_headers() {
if ( current_user_can_bypass_vip_maintenance_mode() ) {
return;
}

/**
* Filters whether to respond with a 503 status code.
*
Expand All @@ -74,11 +68,11 @@ function vip_maintenance_mode_template_redirect() {
*
* @param bool $bool Whether to respond with a 503 status code. Default true.
*/
$respond_503 = apply_filters( 'vip_maintenance_mode_respond_503', true );

if ( true === $respond_503 ) {
status_header( 503 );
$respond_with_status_code = apply_filters( 'vip_maintenance_mode_respond_503', true );
$respond_origin_status_code = apply_filters( 'vip_maintenance_mode_origin_status_code', 503 );

if ( true === $respond_with_status_code ) {
status_header( $respond_origin_status_code, 'Service Unavailable' );
/**
* Filters the Retry-After value used to indicate how long the service is expected to be unavailable.
*
Expand All @@ -96,7 +90,19 @@ function vip_maintenance_mode_template_redirect() {
}

header( 'X-Maintenance-Mode-WP: true' );

}

/**
* Redirects visitors and users without edit_posts capability to the maintenance page
*
* Uses the plugin template when there's no template called `template-maintenance-mode.php` in the theme root folder.
*
* @since 0.1.1
*/
function vip_maintenance_mode_template_redirect() {
if ( current_user_can_bypass_vip_maintenance_mode() ) {
return;
}
if ( locate_template( 'template-maintenance-mode.php' ) ) {
get_template_part( 'template-maintenance-mode' );
} else {
Expand Down
1 change: 1 addition & 0 deletions vipgo-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ function wpcom_vip_maintenance_mode_do_not_respond_503_for_services( $should_set
}

add_filter( 'vip_maintenance_mode_respond_503', 'wpcom_vip_maintenance_mode_do_not_respond_503_for_services', 30 );
add_filter( 'vip_maintenance_mode_origin_status_code', fn() => 583 );