Change default user profile URL - BBpress Plugin

痴心易碎 提交于 2021-01-28 11:31:10

问题


Bbpress Wordpress Plugin have default link user profile url. The link like this: www.example.com/forum/users/(username)

The main purpose in nutshell is: I want to change the url.

Actually, I found the solution but its not perfect. The code like this:

function user_profile_link(){
    $url = 'http://localhost/example.com/profile/';
    $author_id = bbp_get_reply_author_id();
    $user_info = get_userdata($author_id);
   
    echo '<a href="'.$url.''.$user_info->user_login.'"> '. $user_info->display_name.' </a>';

}
add_filter('bbp_get_user_profile_url', 'user_profile_link');

Yes, the code working well. But the outcome is, the user profile URL not replaced and there is double URL like this image below:

image1

I think the problem solved if I display: none it. The code like this:

<style>
.bbp-author-link{
    display: none;
}

</style>

But there is one problem. The new URL that I make appeared beside the breadcrumbs like this image:

image2

I want to remove the link that appeared beside the breadcrumbs. Is there any solution? Any help is appreciated. Thank You


回答1:


In a filter hook, you normally have to override the current value by returning it. Therefore try returning the new value by using the function you already created. It may remove the duplicate.

Also, use site_url() instead of $url variable because there will be issues when you use a hardcoded URL.

function user_profile_link(){
    $author_id = bbp_get_reply_author_id();
    $user_info = get_userdata($author_id);

    return site_url()."/profile/".$user_info->user_login;

}
add_filter('bbp_get_user_profile_url', 'user_profile_link');



回答2:


For this problem, I found the solution.

The code is like this:

function user_profile_link(){

    $author_id = bbp_get_reply_author_id();
    $user_info = get_userdata($author_id);

    $url = site_url()."/profile/".$user_info->user_login;

    return $url;

}
add_filter('bbp_get_user_profile_url', 'user_profile_link');


来源:https://stackoverflow.com/questions/65456090/change-default-user-profile-url-bbpress-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!