Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Use Wordpress maintenance mode instead of custom one
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Simeon committed Aug 10, 2022
1 parent 315a238 commit 38475de
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Studio Meta maintenance mode

Put your site under maintenance with a 503 HTTP status and a dedicated page.
Put your site under maintenance depends on server environment variables.

## Usage

Expand All @@ -9,6 +9,6 @@ Put your site under maintenance with a 503 HTTP status and a dedicated page.
MAINTENANCE_ENABLED=true|false # Enable/Disable maitenance mode.
MAINTENANCE_IPS=42.42.42.42.42 # Exclude a list of IPs from maitenance.
```
2. Customize the maintenance page thanks to `maintenance.php` and `maintenance.css` files.
2. You can customize the maintenance page by adding a `maintenance.php` file in `WP_CONTENT_DIR` (see https://developer.wordpress.org/reference/functions/wp_maintenance/).

> If you use a cache plugin, don't forget to clean caches.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StudiometaMaintenanceMode {
* Constructor.
*/
public function __construct() {
add_action( 'init', array( $this, 'redirect_to_maintenance' ) );
add_filter( 'enable_maintenance_mode', array( $this, 'is_maintenance_mode' ) );
}

/**
Expand All @@ -31,7 +31,6 @@ protected function is_maintenance_mode() {
'true' !== getenv( 'MAINTENANCE_ENABLED' )
|| is_admin()
|| current_user_can( 'administrator' )
|| ! file_exists( __DIR__ . '/maintenance.php' )
|| 'wp-login.php' === $GLOBALS['pagenow']
) {
return false;
Expand All @@ -46,24 +45,6 @@ protected function is_maintenance_mode() {

return true;
}

/**
* Redirect to maintenance mode.
*
* @return void
*/
public function redirect_to_maintenance() {
if ( ! $this->is_maintenance_mode() ) {
return;
}

$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) && 'HTTP/1.1' === $_SERVER['SERVER_PROTOCOL'] ? 'HTTP/1.1' : 'HTTP/1.0';

header( $protocol . ' 503 Service Unavailable', true, 503 );
header( 'Retry-After: 3600' );
include_once __DIR__ . '/maintenance.php';
die();
}
}

new StudiometaMaintenanceMode();
Empty file.

This file was deleted.

0 comments on commit 38475de

Please sign in to comment.