Schedule website launch

332 views Asked by At

I am using WP Maintenance Mode plugin while I am editing my website. I would like to ask how can I schedule the launch of my website, or automatically deactivating the plugin on a specific time. Thanks in advance!

1

There are 1 answers

2
birgire On

Here is one idea:

I'm not sure it's a good idea to deactive the plugin, so you could instead update the plugin options to disable the maintenance mode, at launch time:

/**
 * Plugin Name: Automatic Launch for WP Maintenance Mode 
 * Plugin URI : http://stackoverflow.com/a/20817475/2078474
 * Description: Disable the maintenance mode at launch time, defined by the "countdown" date. Assumes a single site install - not multisite.
 */
! is_admin() && add_action( 'init', function(){

    $opt = get_option( 'wp-maintenance-mode' );

    if( FALSE !== $opt )
    {
         if ( isset( $opt['active'] ) && 1 === (int) $opt['active'] )
         {
             if ( isset( $opt['date'] ) )
             {  
                 // current timestamp - the blog local time 
                 $date_current = current_time( 'timestamp' );  // use time() for GMT

                // countdown date user input 
                $date_launch = DateTime::createFromFormat( 'd-m-Y H:i:s', $opt['date'] );

                // valid date input and it's launch time
                if(    FALSE !== $date_launch   
                    && $date_current > $date_launch->getTimestamp() )
                {
                    // update the options to disable the maintenance screen:
                    $opt['active'] = 0;
                    update_option( 'wp-maintenance-mode', $opt );
                    update_option( 'wp-maintenance-mode-msqld', 0 );
                }
            }
        }
    }
} );

if you use the countdown date:

countdown date

If you need another date you could replace:

$date_launch = DateTime::createFromFormat( 'd-m-Y H:i:s', $opt['date'] ); 

with for example:

$date_launch = DateTime::createFromFormat( 'd-m-Y H:i:s', '24-12-2014 10:11:00' );