试图重定向到用户配置文件

时间:2015-09-23 21:04:35

标签: php wordpress redirect buddypress

使用BuddyPress,我试图将所有注册用户重定向到他们的用户个人资料;但是,当重定向生成的URL时,不包括user_login ...因此,每个用户都会重定向到" domain / members /"。

如何让用户名显示在网址中,然后重定向到以下内容:"域名/成员/用户名/"?

的functions.php

add_filter('login_redirect', function ($redirect_to, $request, $user){
    if (user_can($user, 'registered')){
      $current_user = wp_get_current_user();
      return '/members/' . $current_user->user_login . '/';
    }
}

3 个答案:

答案 0 :(得分:1)

    function redirect_to($new_location) {
      header("Location: " . $new_location);
      exit;
    } 

重定向函数将此函数调用为redirect_to(" redirect_page");

答案 1 :(得分:1)

如WordPress Codex中所述:" $ current_user全局可能在此过滤器运行时不可用。因此,您应该使用$ user global或传递给此过滤器的$ user参数。"

https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

compile 'org.apache.directory.studio:org.apache.commons.codec:1.+'

答案 2 :(得分:1)

更好的方法,不依赖于硬编码的slu ::

return bp_core_get_user_domain( $user->ID );
相关问题