I want to use some type of functionality
if ( $some_condition == false )
{
wp_die();
// Here i want to redirect page on some URL after 10 seconds
}
I need to do it inside a plugin. Is it possible to do that?
wp_die()
terminates the script execution and sends itself a 500 status header (wich can be altered by the third parameter). So you need to send the Refresh
header before the wp_die()
call. I also recommend to print the redirect location to the body because it's up to the client to respect the refresh header.
if ( $condition ) {
$location = 'http://pm.dev';
$timeout = 5;
$message = 'You will be redirected to <a href="' . $location . '">' . $location . '</a>';
$title = 'Your title';
$status = 303; # this might be debatable
header( 'Refresh: ' . $timeout . ';' . $location );
wp_die( $message, $title, array( 'response' => $status ) );
}
(I'm not sure about the correct status code.)
Note: As this code sends HTTP Headers, there must no other output sent to the browser before this code.
wp_die()
function? why not just add in your redirect function with the 10second delay?wp_die()
renders a specific template which might the users are familiar with. It also sends a correct status header by a given integer status code.