wp_die()
终止脚本执行并向自身发送500状态标头(该标头可由第三个参数更改)。所以你需要发送Refresh
header 在wp_die()
呼叫我还建议将重定向位置打印到正文中,因为这取决于客户端是否尊重刷新头。
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 ) );
}
(我不确定是否正确
status code.)
Note: 由于此代码发送HTTP标头,因此在此代码之前不得向浏览器发送其他输出。