Wp Maintenance mode and external cron job

Question

I am using this code

add_action( 'wp_loaded', function() 
{
    global $pagenow;

    // - - - - - - - - - - - - - - - - - - - - - - 
    // Turn on/off you Maintenance Mode (true/false)
    define('IN_MAINTENANCE', true);
    // - - - - - - - - - - - - - - - - - - - - - - 

    if(
        defined( 'IN_MAINTENANCE' )
        && IN_MAINTENANCE
        && $pagenow !== 'wp-login.php'
        && ! is_user_logged_in()
    ) {
        header('HTTP/1.1 503 Service Temporarily Unavailable');
        header( 'Content-Type: text/html; charset=utf-8' );
        if ( file_exists( get_template_directory() . '/maintenance.php' ) ) {
            require_once( get_template_directory() . '/maintenance.php' );
        }
        die();
    }
});

in a custom plugin to temporarily put the site in maintenance mode.
It works fine but I use cron job with external call to the wp-cron.php file.
Is there any way to bypass maintenance mode only for the wp-cron.php file?
Maybe I’m all wrong but thanks to anyone for any input!

0
Daniele As 2 months 0 Answers 15 views 0

Leave an answer