0

I have a registration page 'register' which sends information to a third party server as part of a dual registration process. The 3rd party have a 2 hr weekly maintenance schedule every Friday 9-11pm ET. I wish to redirect users to a new page that just says you can't register during this specified maintenance time period.

I am considering using the below added to functions.php. Is this the right approach, does it look like it would work? I don't want to reset the entire site's time zone either, as not in America, just for this usage.

add_action ( 'template_redirect', 'redirect_from_registration_maintenance' );
function redirect_from_registration_maintenance(){
    date_default_timezone_set('America/Chicago');
    $hour = date('G');
    $minute = date('i');
    $day = date('w');
    $m = $hour * 60 + $minute; // Minutes since midnight.
if ( !is_user_logged_in() && is_page( 'register' )
  && $day == 5 // Friday...
  && $m >= 1260 // ... after 9pm…
  && $m <= 1380 // ... but before 11pm…
) {
    wp_redirect('https://www.example.com/maintenance') ;
exit();
    }
}

Thanks

1
  • Well have tested it with people in 2 differing timezones and all seems to be working – edindubai May 12 '20 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.