2013-12-23 10:54
浏览 49


i have a custom theme with frontend E-Mail and Facebook login. 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? I tried this:

<?php echo the_author_ID(); ?>

But it does not works for the admin role and Users who logged in with facebook? The id shows up with hovering in the backend... Any idea?

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!

图片转代码服务由CSDN问答提供 功能建议

我有一个自定义主题,前端电子邮件和Facebook登录。 注册后,默认情况下每个用户都会获得作者角色。

如何通过在后端悬停用户名来回显前端显示的USERS ID? 我试过这个:

 &lt;?php echo the_author_ID();  ?&gt; 

但它不适用于管理员角色和使用Facebook登录的用户? id出现在后端盘旋......任何想法?

更新:我将显示已注册用户的ID - 在他们的前端author.php而不是ID 当前用户的登录状态!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douzong5057 2013-12-23 11:17

    It looks like you are looking for this,




    function has been deprecated.

    打赏 评论
  • drgwsx8405 2013-12-23 10:58

    It is specific only to users with user_role=author If you want admin roles and users from facebook login you can try get_current_user_id()

    打赏 评论
  • dongyi2083 2013-12-23 11:05

    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 :

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


    You can also try current user object (WP_User).Retrieve the current user object (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(); ?> 
    打赏 评论

相关推荐 更多相似问题