Search code examples
phpwordpresscron

How to run php script even in maintenance mode (wordpress)


I would like to run an external php script (with wp-load.php) even if the site is in maintenance mode.

I'm using a plugin to put my website in maintenance (Coming soon)

My script starts with :

include( '/path/wp-load.php' );

Is it possible ?


Solution

  • It`s been awhile since the moment of the question, but maybe a solution will help someone in the future.

    Just define IS_WP_CLI variable in the beginning of your script .

    ...
    define('IS_WP_CLI', true); // Avoid maintenance mode
    require_once HOME_PATH . '/wp-load.php';
    ...
    

    If IS_WP_CLI defined -> maintenance mode will not be instantiated.

    if (defined('IS_WP_CLI')) { return ; }
    

    Now you can run cli scripts even if maintenance mode is active.