自定义登录页面重定向到已登录用户配置文件页面

时间:2014-04-09 作者:Preksha

如果我点击sign in 然后应该转到登录页面。

问题是,当我放置链接时redirect_to 主页,但我想转到用户配置文件页。

我不想在登录后使用插件重定向到个人资料页面。

我有用户配置文件的代码-<a href="<?php echo bp_loggedin_user_domain(); ?>/profile/edit/"><span>My Profile</span></a>

我想把这个链接放到<input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />

这可能吗?还有其他建议吗?

3 个回复
SO网友:Margaret

如果使用内置函数创建登录框,其中一个参数是重定向。wp_login_form function reference

要获取您的个人资料链接,请在以管理员身份登录时进行检查。链接相同,但提供的选项不同。默认值为yoursite。com/wp管理员/配置文件。php

SO网友:ma_dev_15

您可以在中的函数中编写代码functions.php 并为此添加操作

add_filter( \'login_redirect\', \'my_rd\', 10, 3 );

Function my_rd(){

}

SO网友:Ravi Patel

IF you wants to use plguin bp redirect to profile go here:

add_filter( \'bp_login_redirect\', \'bpdev_redirect_to_profile\', 11, 3 );

function bpdev_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user ){

    if( empty( $redirect_to_calculated ) )
        $redirect_to_calculated = admin_url();

    //if the user is not site admin,redirect to his/her profile

    if( isset( $user->ID) && ! is_super_admin( $user->ID ) )
        return bp_core_get_user_domain( $user->ID );
    else
        return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/

}
结束