简体   繁体   English

Buddypress 重定向到用户个人资料页面

[英]Buddypress redirection to user profile page

I'm trying to redirect to the user profile page after login un Buddypress.我试图在登录 un Buddypress 后重定向到用户个人资料页面。 I use this code but it omits the username from the URL for redirection.我使用此代码,但它从 URL 中省略了用于重定向的用户名。 what do I do?我该怎么办?

function custom_login_redirect_to($user_login, $user) {
        bp_core_redirect( get_option('siteurl') ."/profile/" . bp_core_get_user_displayname( bp_loggedin_user_id() ) ."/profile/" );
}
add_action('wp_login', 'custom_login_redirect_to', 10, 2);

This is what is returned in the URL https://mywebsite/profile/profile instead of https://mywebsite/profile/username/profile这是在 URL https://mywebsite/profile/profile而不是https://mywebsite/profile/username/profile

这种方法更便携:

bp_core_redirect( bp_core_get_user_domain( $user->id ) );

Thanks all.谢谢大家。 I was not getting the current user that's why it's failing.我没有得到当前用户,这就是它失败的原因。 The code that works.有效的代码。

function custom_login_redirect_to($user_login, $user) {
    $username = bp_core_get_username( $user->id );
    bp_core_redirect( get_option('siteurl') ."/profile/" . $username ."/profile/" );
}
add_action('wp_login', 'custom_login_redirect_to', 10, 2); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM