WordPress - Custom plugin for maintenance mode not work

195 Views Asked by At

I have created a simple plugin to activate maintenance mode in wp with this code


class Maintenance {
  
  public function __construct()
  {
     add_action('get_header', [$this, 'enable_maintenance_mode']);
  }

  public function enable_maintenance_mode()
  {
     if(!current_user_can('edit_themes') || !is_user_logged_in()){
        wp_die('Website under maintenance');
     }
  }

}

new Maintenance();

Anyway the website is loaded and the maintenance mode isn't enabled. I've also tried to add the function into the deafult wordpress theme but not work. Is there any way to fix it without installing third party plugins?

0

There are 0 best solutions below