Advertisement
drkskwlkr

WordPress Maintenance

May 25th, 2023 (edited)
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | Source Code | 0 0
  1. <?php add_action('template_redirect', function () {
  2.     $secrete_pass = 'allow-access';
  3.     $maintenance_url = '/maintenance/';
  4.     $protocol = 'http://';
  5.     $user_is_admin = current_user_can('manage_options');
  6.    
  7.     if ($user_is_admin) return;
  8.    
  9.     if ( ($_GET['access'] ?? '') === $secrete_pass ) return;
  10.    
  11.     if ( ($_SERVER['HTTPS'] ?? '') === 'on' || ($_SERVER['HTTPS'] ?? 0) === 1 ||      ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? 'http') === 'https' )
  12.     {
  13.         $protocol = 'https://';
  14.     }
  15.    
  16.     $path = wp_make_link_relative( $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  17.    
  18.     if ( $path !== $maintenance_url ) exit( wp_redirect( home_url( $maintenance_url ), 307 ));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement