【问题标题】:Buddypress redirection to user profile pageBuddypress 重定向到用户个人资料页面
【发布时间】:2019-12-20 12:15:33
【问题描述】:

我正在尝试在登录 un Buddypress 后重定向到用户个人资料页面。我使用此代码,但它省略了 URL 中的用户名以进行重定向。我该怎么办?

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);

这是在 URL 中返回的内容 https://mywebsite/profile/profile 而不是 https://mywebsite/profile/username/profile

【问题讨论】:

    标签: wordpress url redirect buddypress


    【解决方案1】:

    这种方法更便携:

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

    【讨论】:

      【解决方案2】:

      谢谢大家。我没有得到当前用户,这就是它失败的原因。 有效的代码。

      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); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-30
        • 2018-12-12
        • 2016-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-28
        相关资源
        最近更新 更多