0

我有一个用户登录的 iframe 弹出窗口。问题是,当他们登录时,重定向会在 iframe 内加载页面而不是父元素。

我知道我需要在某处插入此代码才能使这项工作:

window.top.location.href = "http://www.site.com"; 

重定向单元的代码如下:

function login_redirect( $redirect_to, $request, $user ) {
    global $theme_my_login;

    // Determine the correct referer
    if ( !$http_referer = wp_get_original_referer() )
        $http_referer = wp_get_referer();

    // Remove some arguments that may be present and shouldn't be
    $http_referer = remove_query_arg( array( 'instance', 'action', 'checkemail', 'error', 'loggedout', 'registered', 'redirect_to', 'updated', 'key', '_wpnonce', 'reauth' ), $http_referer );

    // Make sure $user object exists and is a WP_User instance
    if ( !is_wp_error( $user ) && is_a( $user, 'WP_User' ) ) {
        if ( is_multisite() && empty( $user->roles ) ) {
            $user->roles = array( 'subscriber' );
        }
        $redirection = array( 'login_type' => 'default' );
        foreach ( (array) $user->roles as $role ) {
            if ( $theme_my_login->options->get_option( array( 'redirection', $role ) ) ) {
                $redirection = $theme_my_login->options->get_option( array( 'redirection', $role ) );
                break;
            }
        }
        if ( 'referer' == $redirection['login_type'] ) {
            // Send 'em back to the referer
            $redirect_to = $http_referer;
        } elseif ( 'custom' == $redirection['login_type'] ) {
            // Send 'em to the specified URL
            $redirect_to = $redirection['login_url'];
            // Allow a few user specific variables
            $replace = array( '%user_id%' => $user->ID, '%user_login%' => $user->user_login );
            $redirect_to = str_replace( array_keys( $replace ), array_values( $replace ), $redirect_to );
        }
    }

    // If a redirect is requested, it takes precedence
    if ( !empty( $request ) && admin_url() != $request && admin_url( 'profile.php' ) != $request )
        $redirect_to = $request;

    // Make sure $redirect_to isn't empty
    if ( empty( $redirect_to ) )
        $redirect_to = get_option( 'home' );

    return $redirect_to;
}
4

0 回答 0