php 按 ID 获取 Wordpress 用户个人资料网址/链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20724301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:28:10  来源:igfitidea点击:

Get Wordpress User Profile Url/Link by ID

phpjquerywordpress

提问by NewUser

I managed to show up the users Profile Images from the mainsite xxxxx.com/ in my bbpress forum xxxxx.com/forum/ with the following code:

我设法在我的 bbpress 论坛 xxxxx.com/forum/ 中使用以下代码显示来自主站点 xxxxx.com/ 的用户个人资料图片:

<?php $user_info = get_user_by('id', $wp_query->query_vars['author']); echo get_avatar($user_info->ID, '150'); ?>

Question:

题:

How can i get the Users Profile URL/LINK like xxxxxx.com/user/username with the same method?

如何使用相同的方法获取用户配置文件 URL/LINK,如 xxxxxx.com/user/username?

Thank you so much!

非常感谢!

回答by Reza Mamun

To get user's profile link like xxxxxx.com/author/username/ use the following function:

要获取用户的个人资料链接,如 xxxxxx.com/author/username/,请使用以下函数:

<?php get_author_posts_url( $author_id, $author_nicename ); ?>

Here is the documentation.

这是文档

回答by Mohan Dere

If you want to edit a user from admin side then you can use this:

如果要从管理员端编辑用户,则可以使用以下命令:

function get_admin_edit_user_link( $user_id ){

    if ( get_current_user_id() == $user_id )
       $edit_link = get_edit_profile_url( $user_id );
    else
       $edit_link = add_query_arg( 'user_id', $user_id, self_admin_url( 'user-edit.php'));

    return $edit_link;
}

回答by M Javid Naseem

User Page URL is working

用户页面 URL 有效

wp function => get_author_posts_url( int $author_id, string $author_nicename = '' )

wp 函数 => get_author_posts_url( int $author_id, string $author_nicename = '' )

<?php echo get_author_posts_url($user_id); ?>

output: https://example.com/author/username/

Reference Link : https://codex.wordpress.org/Function_Reference/get_the_author_link

参考链接:https: //codex.wordpress.org/Function_Reference/get_the_author_link

回答by realmag777

For getting user link with its nice name use 2 functions:

要使用其好听的名称获取用户链接,请使用 2 个函数:

回答by Piotr Kaluza

This function should help: https://codex.wordpress.org/Template_Tags/the_author_metathe_author_meta( $field, $userID );

这个函数应该有帮助:https: //codex.wordpress.org/Template_Tags/the_author_metathe_author_meta( $field, $userID );

for profile link you'll need 'user_url' for the field

对于个人资料链接,该字段需要“user_url”