Created
August 10, 2018 04:08
-
-
Save hideokamoto/78dc03d9ef2bb7826c6931e1f43a2b57 to your computer and use it in GitHub Desktop.
ログインしていない時は、SPAに強制リダイレクト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'init', 'redirect_to_spa' ); | |
function redirect_to_spa() { | |
if ( ! is_user_logged_in() ) { | |
$uri = $_SERVER["REQUEST_URI"]; | |
if ( ! preg_match( '/^\/wp-login.php/', $uri ) && ! preg_match( '/^\/wp-admin/', $uri ) && ! preg_match( '/^\/wp-json/', $uri ) && ! preg_match( '/^\/feed/', $uri ) ) { | |
$url = 'https://wp-kyoto.net' . $uri; | |
wp_redirect( $url, 301 ); | |
exit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment