admin管理员组

文章数量:1316004

Case: There is natural disaster or terrorist attack etc. Admin logins to site and enables "crisis mode". All traffic gets redirected to crisis page.

I found this code from another answer which deals the redirect part. So how to create a switch to admin area which executes the code.

add_action( 'template_redirect', function() {
    if ( is_page( 813 ) ) {
        return;
    }

    wp_redirect( esc_url_raw( home_url( 'index.php?page_id=183' ) ) );
    exit;
} );

Answer to the question: I fiqured out a solution with ACF option field.

  1. Create option page
  2. Add 1/0 Switch to option page
  3. Add code to child themes functions.php
add_action( 'template_redirect', function() {
  if ( is_page( 853 ) ) {
    return;
  }
  if(get_field('crisis', 'option')) {
    wp_redirect( esc_url_raw( home_url( 'index.php?page_id=853' ) ) );
    exit;
  }
} );
  1. Done.

Do you have a better approuch to this?

本文标签: