Giter Club home page Giter Club logo

maintenance-mode-wp's Introduction

Maintenance Mode

Shut down your site for a little while and do some maintenance on it!

Installation and activation

  1. Add the plugin to the /plugins directory of an application's GitHub repository.
  2. Define the VIP_MAINTENANCE_MODE constant as true in vip-config/vip-config.php.
  3. Activate the plugin in the WordPress Admin dashboard Plugins screen.

Custom Template

To add a custom template and messaging:

  • Create a template in your theme's root folder named template-maintenance-mode.php.
  • This should be a simple HTML page that includes the message you want to show your visitors.
  • Note: the template should include wp_head() and wp_footer() calls.

Additional Configurations

Using filters and conditionals, you can customize the behavior of the Maintenance Mode plugin based on your needs. These options rely on the plugin being installed as described above.

Selectively Load Maintenance Mode Configure Maintenance Mode to only display for a specific network site. Code similar to this example must be added to the vip-config/vip-config.php file:

$site_name = $_SERVER['SERVER_NAME'];
$lockdown = false;

if ( false !== strpos( $site_name, 'url-to-enable-maintentance-mode' ) ) {
    // Set lockdown
    $lockdown = true;
}
// Set maintenance plugin
define( 'VIP_MAINTENANCE_MODE', $lockdown );

Enable WordPress REST API Configure Maintenance Mode to keep the WordPress REST API enabled even though the rest of the site is not accessible. Note that this code should be added to a file located within the client-mu-plugins directory:

// Generally allow API access
add_filter( 'vip_maintenance_mode_restrict_rest_api', '__return_false' );

You can also choose to enable the REST API only in more narrow use-cases:

add_filter( 'vip_maintenance_mode_restrict_rest_api', 'x_mm_allow_api' );

function x_mm_allow_api( $default ) {
	if (my_check() ) { 
                           return false;
             }

	return true;
}

Default template screenshots

On Twenty Twenty-One:
Screenshot of active Maintenance mode on Twenty Twenty-One

On Twenty Twenty:
Screenshot of active Maintenance mode on Twenty Twenty

On Twenty Nineteen:
Screenshot of active Maintenance mode on Twenty Nineteen

On Twenty Seventeen:
Screenshot of active Maintenance mode on Twenty Seventeen

Changelog

0.2.2

  • Stop returning a 503 to Jetpack requests to prevent broken connection verification

0.2.1

  • Stop returning a 503 to Nagios on WPCom and VipGo to prevent alerting as a server error

0.2.0

  • Return a 503 header while maintenance mode is active (props benoitchantre)
  • Add an admin bar notice when Maintenance Mode is on (props benoitchantre)

0.1.0

  • Initial plugin

maintenance-mode-wp's People

Contributors

anigeluk avatar benoitchantre avatar david-binda avatar emrikol avatar maevelander avatar mattoperry avatar mjangda avatar philipjohn avatar rebeccahum avatar rinatkhaziev avatar spacedmonkey avatar trepmal avatar whyisjake avatar yolih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

maintenance-mode-wp's Issues

Styles for the maintenance page

For now, the maintenance page doesn't look enough like a maintenance page.
I think the default template should be a bit more styled.

Here are some neutral examples that could inspire the styles for the maintenance page.

capture d ecran 2017-03-28 a 22 55 33

capture d ecran 2017-03-28 a 22 52 41

maintenance_page-59575dad

I prefer the latest (except the color which I find a bit aggressive): the message is very clear.

What are your thought on this?
Do you have some examples to share?

Maintenance message can be unreadeable

Here are some screenshots with Maintenance Mode enabled on the latests default themes.

Twenty Seventeen: ok
capture d ecran 2017-03-28 a 21 49 44

Twenty Sixteen: lack of constrast
capture d ecran 2017-03-28 a 21 49 26

Twenty Fifteen: positioned behind another element
capture d ecran 2017-03-28 a 21 49 10

A simple way to solve the lack of readability would be to use a fullscreen container with a background color and a high z-index.

Users are unable to log in

When the maintenance mode is enabled, users cannot log in and update the website.

The login page should always be accessible.

When users try to log in without the required capability, they should be redirected to the maintenance page.

Add linting

Just basic PHP linting right now is enough, hooked into Travis.

undefined vip_maintenance_mode_maybe_restrict_rest_api

 Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'vip_maintenance_mode_maybe_restrict_rest_api' not found or invalid function name

It should be vip_maintenance_mode_restrict_rest_api

Enable via UI rather than code

Enabling and disabling via code is cumbersome and not very efficient or convenient for our needs. Would be much more ideal if this could be controlled from the admin dashboard.

REST API error code: 401 instead of 503

Actually, the error code is a 401, meaning a client error (wrong authentication credentials).
I think it should be a 503 to describe a server error.

The error message could be also improved more descriptive, for example : This site is under maintenance, the REST API access is currently restricted. instead of REST API access is currently restricted while we refresh things a bit.

Plugin flags warnings on WPVIP

When installed on WPVIP, the VIP Code Analysis Bot flags the following warnings:

plugins/maintenance-mode-wp-main/vipgo-helper.php - line 14

⚠️ Warning( severity 10 ): Detected usage of a non-sanitized input variable: $_SERVER['HTTP_USER_AGENT'] (WordPress.Security.ValidatedSanitizedInput.InputNotSanitized).

plugins/maintenance-mode-wp-main/wpcom-helper.php - line 14

⚠️ Warning( severity 10 ): Detected usage of a non-sanitized input variable: $_SERVER['HTTP_USER_AGENT'] (WordPress.Security.ValidatedSanitizedInput.InputNotSanitized).`

plugins/maintenance-mode-wp-main/tests/bootstrap.php - line 8

⚠️ Warning( severity 3 ): File inclusion using variable ($_tests_dir). Probably needs manual inspection (WordPressVIPMinimum.Files.IncludingFile.UsingVariable).

plugins/maintenance-mode-wp-main/tests/bootstrap.php - line 15

⚠️ Warning( severity 3 ): File inclusion using variable ($_tests_dir). Probably needs manual inspection (WordPressVIPMinimum.Files.IncludingFile.UsingVariable).

Given the plugin is recommended as part of a multisite launch in VIP's documentation, this should likely be fixed.

Protect API endpoints

When maintenance mode is enabled, we should make sure that REST API and XML-RPC endpoints are restricted to the proper capabilities as well.

Indicate that maintenance mode is enabled

There's no hint that maintenance mode is enabled. You can easily forget to disable the plugin if you don't check the website in a private window.

I think something in the admin bar would be necessary.

Send 200 response for wpcom nagios mobile check

We have an exception in wpcom-helper.php that sends a 200 for Nagios checks, but that misses the mobile checks.

Mobile checks are performed with a UA of (exactly) iphone, so we can also check for that exact string to detect Nagios mobile. That shouldn't affect real iphones as they won't have that exact UA, and will still see Maintenance Mode anyway.

No doctype

The template provided in the plugin has no declared doctype.

Required capability: Redirect to maintenance mode page on login

Currently, we have the vip_maintenance_mode_required_cap filter that check's for a required capability (edit_posts by default) and if the user does NOT have that capability, it will redirect them to the Maintenance Mode page.

However, this is hooked into template_redirect so it only happens on the frontend of the site. If they log in they will still be redirected to the Dashboard. If they try to view the site, they will see the Maintenance Mode page.

I think it makes sense to redirect everywhere and not just on the frontend.

Possible use case:
I am a site Admin and I want to enable maintenance mode and restrict specific users from logging in. I add a filter to restrict all non-admins from being able to log in, and I do some maintenance tasks while confidently knowing no one else is logging in to update/change data.

Thoughts?
cc @anigeluk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.