How to programmatically put wordpress in maintenance mode

I used this code for several years now:add_action('wp_loaded', 'check_maintenance_mode');function c

I used this code for several years now:

add_action('wp_loaded', 'check_maintenance_mode');
function check_maintenance_mode(){
  global $pagenow;
  if(defined('IN_MAINTENANCE') && IN_MAINTENANCE && $pagenow !== 'wp-login.php' && !is_user_logged_in()){
    header('HTTP/1.1 Service Unavailable', true, 503);
    header('Content-Type: text/html; charset=utf-8');
    if(file_exists(WP_CONTENT_DIR . '/maintenance.php')){
      require_once( WP_CONTENT_DIR . '/maintenance.php' );
    }
    die();
  }
}

The IN_MAINTENANCE and WP_CONTENT_DIR constants are initialised and setted by me.

Anyway, this code suddenly stopped to work. The website is always visible even with IN_MAINTENANCE setted to true. By logging from the function, I can confirm that all the conditions are true and it really throw the headers and require the maintenance.php file, but it doesn't.

Any idea?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745330105a4622837.html

相关推荐

  • How to programmatically put wordpress in maintenance mode

    I used this code for several years now:add_action('wp_loaded', 'check_maintenance_mode');function c

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信