I've got a domain that is under development and have created a plugin that uses wp_die() in a function I wrote. It must be checked against user auth which is conflicting with my plugin because init checks the user auth before wp_head.

function coming_soon(){



echo '<meta http-equiv="refresh" content="0;URL=/cgi-sys/defaultwebpage.cgi">';


add_action('wp_head', 'coming_soon', 10);


It should check if a user is logged in and if not wp_die and echo the redirect. As is, this does exactly what it is intended, I just need it to check a condition if is logged in else.



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



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' )

add_action('init', 'coming_soon', 5);
| improve this answer | |
  • I see what you did there. But it hooks too early. I'm using the wp_die() as an action in wp_head. – Jarmerson Aug 15 '16 at 23:52
  • This still works, but you can definitely hook in wp_head if that is what you need :) – bynicolas Aug 16 '16 at 0:07
  • It does. However in my scenario I'm outputting the function in wp_head which is loaded after the user has been auth whereas I need to check the user after wp_die in order to get the coming soon page to show. – Jarmerson Aug 16 '16 at 0:11
  • oh! well that's a total different scenario! I thought you only wanted to die() requests for non logged in users! Maybe try updating your question with that bit of info... I'll update my answer to reflect this new information – bynicolas Aug 16 '16 at 0:16
  • I see you updated your question, now just to make sure I understand what you are trying to achieve. If a user is not logged in, he gets a message/HTML that tells him something along the lines "website coming soon" right? do you have any other specification for that coming soon page? – bynicolas Aug 16 '16 at 0:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.