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 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决