我正在编辑网站时使用WP维护模式插件。我想问一下如何安排我的网站启动,或者在特定时间自动停用插件。提前谢谢!
答案 0 :(得分:0)
这是一个想法:
我不确定取消插件是个好主意,所以你可以在发布时更新插件选项以禁用维护模式:
/**
* 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 );
}
}
}
}
} );
如果您使用倒计时日期:
如果您需要另一个日期,可以替换:
$date_launch = DateTime::createFromFormat( 'd-m-Y H:i:s', $opt['date'] );
例如:
$date_launch = DateTime::createFromFormat( 'd-m-Y H:i:s', '24-12-2014 10:11:00' );