Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use enable_maintenance_mode filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 18, 2023
5 minutes read

As we dive into the world of WordPress hooks, let’s talk about the enable_maintenance_mode filter. This filter kicks in before plugins have a chance to use it, making it perfect for non-web runtimes. If the filter returns true, the maintenance mode gets activated, and the request ends. On the flip side, if it returns false, the request proceeds even if maintenance mode should normally be active. You can register this filter using the add_filter function, whether in your theme’s functions.php file or a custom WordPress plugin. At WePlugins, we recommend creating a custom plugin to ensure nothing breaks during theme updates.

Below, you’ll find live examples of how to use the enable_maintenance_mode filter:

Example 1: Basic Usage

Here’s a straightforward example of applying the filter in your WordPress setup.

    apply_filters( 'enable_maintenance_mode', bool $enable_checks, int $upgrading )
    

Example 2: Modifying Defaults

In this example, we define a function weplugins_modify_enable_maintenance_mode_defaults which takes two parameters. We then register this function using add_filter.

    function weplugins_modify_enable_maintenance_mode_defaults($enable_checks, $upgrading) { 
        // Update the $enable_checks variable according to your website requirements and return this variable.
        // You can modify the $enable_checks variable conditionally too if you want.
        return $enable_checks; 
    }
    // add the filter
    add_filter( "enable_maintenance_mode", "weplugins_modify_enable_maintenance_mode_defaults", 10, 2 );
    

Example 3: Removing a Hook

If you need to remove a registered hook, use the remove_filter function as shown below. Ensure you provide the same callback function name, priority, and number of arguments.

    remove_filter( "enable_maintenance_mode", "weplugins_modify_enable_maintenance_mode_defaults", 10, 2 );
    

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook or need customization, don’t hesitate to contact us. We’re here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.