EDIT
You just need to add a custom hook to anything after parse_request
and attach your coming soon content or redirect to that hook as you see fit. Hooking earlier then parse_request
will cause WP to not be able to redirect /wp-admin/ to wp-login.php.
You could also use php redirect if that is the behaviour you are looking for. Like so
function coming_soon(){
if( ! is_user_logged_in() && $GLOBALS['pagenow'] !== 'wp-login.php' )
do_action( 'coming_soon_content' );
}
add_action('parse_request', 'coming_soon', 5);
add_action( 'coming_soon_content', 'my_coming_soon_page' );
function my_coming_soon_page(){
echo '<h2>Coming soon!</h2>'; // your coming soon content or
echo '<meta http-equiv="refresh" content="0;URL=/cgi-sys/defaultwebpage.cgi">'; // if using meta refresh
header('Location: http://www.example.com/'); // if using php header()
exit; // if using header()
wp_die(); // this is where die should be
}
ORIGINAL ANSWER
Just check if user is logged with is_user_logged_in()
. Additionally, I would hook early (init) and check that we are not on the wp-login.php page so a user can still login! This will make sure nothing runs on your site if someone is not logged in. using wp_head
as a hook, you still have a lot of things that are loaded before the check is made.
function coming_soon(){
if( ! is_user_logged_in() && $GLOBALS['pagenow'] !== 'wp-login.php' )
wp_die();
}
add_action('init', 'coming_soon', 5);