简体   繁体   English

如何在author.php中回显Wordpress作者ID?

[英]How to echo Wordpress Author ID in author.php?

i have a custom theme with frontend E-Mail and Facebook login. 我有一个自定义主题与前端电子邮件和Facebook登录。 Every user gets the author role by default after registration. 注册后,默认情况下每个用户都会获得作者角色。

How can i echo the USERS ID in the frontend wich shows up by hovering about the users name in the backend? 如何通过在后端徘徊用户名来回显出前端的USERS ID? I tried this: 我试过这个:

<?php echo the_author_ID(); ?>

But it does not works for the admin role and Users who logged in with facebook? 但它不适用于管理员角色和登录Facebook的用户? The id shows up with hovering in the backend... Any idea? id出现在后端徘徊......有什么想法吗?

Update: i will show the IDs of the users who are registered - in their frontend author.php AND not the ID of the current user who is logged in! 更新:我将在其前端author.php中显示已注册用户的ID,而不是当前登录用户的ID!

它仅适用于具有user_role=author用户如果您想要从facebook登录的管理员角色和用户,您可以尝试get_current_user_id()

It looks like you are looking for this, 看起来你正在寻找这个,

the_author_meta("ID");

The

the_author_ID();

function has been deprecated. 函数已被弃用。

You can use get_current_user_id() .Returns the ID of the current viewer if they are logged in. Returns 0 if the viewer is not logged in. you can try for current user like this : 您可以使用get_current_user_id() 。如果登录,则返回当前查看器的ID。如果查看者未登录,则返回0.您可以尝试当前用户,如下所示:

 <?php
$user_id = get_current_user_id();
if ($user_id == 0) {
    echo 'You are currently not logged in.';
} else {
    echo 'You are logged in as user '.$user_id;
}
?> 

OR 要么

You can also try current user object (WP_User) .Retrieve the current user object (WP_User). 您还可以尝试current user object (WP_User)检索当前用户对象(WP_User)。

$current_user = wp_get_current_user();
    /**
     * @example Safe usage: $current_user = wp_get_current_user();
     * if ( !($current_user instanceof WP_User) )
     *     return;
     */
    echo 'Username: ' . $current_user->user_login . '<br />';
    echo 'User email: ' . $current_user->user_email . '<br />';
    echo 'User first name: ' . $current_user->user_firstname . '<br />';
    echo 'User last name: ' . $current_user->user_lastname . '<br />';
    echo 'User display name: ' . $current_user->display_name . '<br />';
    echo 'User ID: ' . $current_user->ID . '<br />';

 <?php wp_get_current_user(); ?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM