更改默认用户配置文件 URL - BBpress 插件 [英] Change default user profile URL - BBpress Plugin

查看:37
本文介绍了更改默认用户配置文件 URL - BBpress 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bbpress Wordpress 插件具有默认链接用户配置文件 url.链接如下:www.example.com/forum/users/(username)

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

是的,代码运行良好.但结果是,用户个人资料 URL 没有被替换,并且有如下图所示的双重 URL:

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

如果我显示:none it,我认为问题解决了.代码如下:

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

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

</style>

但是有一个问题.我创建的新 URL 出现在面包屑旁边,如下图所示:

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

推荐答案

在过滤器挂钩中,您通常必须通过返回当前值来覆盖它.因此,尝试使用您已经创建的函数返回新值.它可能会删除重复项.

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.

另外,使用 site_url() 代替$url 变量,因为使用硬编码 URL 时会出现问题.

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

这篇关于更改默认用户配置文件 URL - BBpress 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆