WordPress登录redirect_to无效

  发布于 2023-02-13 10:30

我正在使用WordPress 3.7.1开发一个网站,并尝试在登录时通过redirect_to URL参数重定向用户.

我已经验证登录表单后端看到redirect_to GET参数,并且登录提交包含redirect_to POST值...但那些东西不起作用.

删除了链接和用户凭据

登录后(对于我的Admin acct和本帖中提供的订阅者帐户),用户将被带到WP仪表板而不是redirect_to参数中的URL.

我确实设置了allowed_redirect_hosts,并在自定义插件文件中使用以下代码(这就是这个).

add_filter( 'allowed_redirect_hosts' , 'glue_allowed_redirect_hosts' , 10 );
function glue_allowed_redirect_hosts($content){
    $content[] = 'app.realestategradschool.com';
    $content[] = 'dev-app.realestategradschool.com';
    $content[] = 'app.realestategradschool.local';
    return $content;
}

我已经禁用了所有其他插件,试图对此进行故障排除.

编辑:我不能使用login_redirect,因为我不打算重定向所有登录...只有当访问者从其他站点发送到登录页面时(使用oAuth将其登录... oAuth工作...只是没有重定向)

编辑:工作解决方案:

function glue_login_redirect($redirect_to,$request='',$user=null){
    //using $_REQUEST because when the login form is submitted the value is in the POST
    if(isset($_REQUEST['redirect_to'])){
        $redirect_to = $_REQUEST['redirect_to'];
    }
    return $redirect_to;
}
add_filter('login_redirect','glue_login_redirect',999);

Bilal.. 7

你可以使用login_redirect过滤器.请参见 http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

我想这就是你要找的东西.

这通常会重定向所有登录.为了能够仅在您需要时重定向,您可以在URL中使用查询字符串参数.如果参数存在重定向,请检查该参数.

1 个回答
  • 你可以使用login_redirect过滤器.请参见 http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

    我想这就是你要找的东西.

    这通常会重定向所有登录.为了能够仅在您需要时重定向,您可以在URL中使用查询字符串参数.如果参数存在重定向,请检查该参数.

    2023-02-13 10:33 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有