使用wp_die后,在10秒内将用户重定向到特定链接

时间:2014-06-12 作者:Xing Lee

我想使用某种类型的功能

if ( $some_condition == false )
{
    wp_die();
    // Here i want to redirect page on some URL after 10 seconds
}
我需要在插件中完成它。有可能做到吗?

1 个回复
SO网友:David

wp_die() 终止脚本执行并向自身发送500状态标头(该标头可由第三个参数更改)。所以你需要发送Refresh headerwp_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标头,因此在此代码之前不得向浏览器发送其他输出。

结束

相关推荐

使用.htaccess强制HTTPS-卡在重定向循环中

我的Wordpress网站位于示例中。com/wordpress和我需要里面的所有东西都只能使用SSL访问。我创建了一个。重定向http->https的htaccess规则:RewriteEngine On RewriteRule ^/?(.*) https://%{SERVER_NAME}/wordpress/directory/$1 [R,L] 实施此规则后,网站将无法访问,因为它被困在重定向循环中。我做错了什么?我的Wordpress。htaccess:<IfModul