doumizhi0809 2014-01-29 21:57
浏览 126
已采纳

如何将redirect_to从登录传递到Wordpress中的注册页面

I'm trying to pass the redirect_to querystring to the registration page so individuals who don't have a login, need to register, get redirected back to login page's referrer. I used

wp_login_url(get_permalink($event->get_id())) 

to add the redirect_to querystring to the login page, and tried to use get get_query_var( 'redirect_to' ), but nothing happens.

Anyone know how to add the login querystring on redirect to the register page?

  • 写回答

2条回答 默认 最新

  • dsdzz04802 2014-01-30 01:23
    关注

    If you're looking to maintain the redirect_to url from the login to the registration and back to the login page, so the user can just enter their password once received by email, and still return to the original referrer this is the full solution.

    function custom_register_url( $registration_url ) {
        $redirect_to = $_GET["redirect_to"];
        $eab_msg = $_GET["eab"];
    
        if( $redirect_to != "" && $eab_msg != ""  ) {
            // change query name values to prevent default behaviour (redirect_to to uct_redirect)
            $registration_url = sprintf( '<a href="%s&%s&%s">%s</a>', esc_url( wp_registration_url() ), "uct_redirect=" . urlencode($redirect_to), "uct_eab=" . urlencode($eab_msg), __( 'Register' ) );
        }
    
        return $registration_url;
    }
    add_filter( 'register', 'custom_register_url' );
    
    function custom_registration_redirect($registration_redirect) {
        $redirect_to = $_GET["uct_redirect"];
        $eab_msg = $_GET["uct_eab"];
    
        if( $redirect_to != "" && $eab_msg != ""  ) {
            // change query names back to original values (uct_redirect to redirect_to)
            $registration_redirect = wp_login_url( $redirect_to ) . '&eab=' . $eab_msg;
        }
    
        return $registration_redirect;
    }
    add_filter( 'registration_redirect', 'custom_registration_redirect' );
    

    Just drop it in functions.php. Hope this helps someone Cheers!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值