4

I am building a maintenance plugin where I will invoke 503 Header responses when the plugin is activated. However, I also make sure other pages get redirected to the homepage. But the redirection is not working when 503 header is already applied.

For example:

When I visit homepage all seems good. I can see the 503 headers. But when I go to About page, 503 is there but the page is not redirecting to homepage and just showing a blank while page. Here are the codes

For the header responses

function use_header_declaration(){

    $mins = get_option('ac_m_retry_time');
    $backtime = ($mins * 60);
    header("HTTP/1.1 503 Service Temporarily Unavailable");
    header("Status: 503 Service Temporarily Unavailable");
    header("Retry-After: $backtime");
    }
add_action('send_headers', 'use_header_declaration');

For the redirection

function ac_wc_my_acct_redirect()
{

    if (!is_front_page() && !is_user_logged_in())  {
        ob_start();
        wp_redirect(home_url());
        exit;
    }
}
add_filter('template_redirect', 'ac_wc_my_acct_redirect', 99);

Thanks in advance.

Ayanize
  • 485
  • 1
  • 4
  • 21

0 Answers0