{"id":2002,"date":"2019-04-22T13:03:45","date_gmt":"2019-04-22T12:03:45","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2002"},"modified":"2026-02-20T19:27:33","modified_gmt":"2026-02-20T19:27:33","slug":"access-user-info","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/users\/access-user-info","title":{"rendered":"Access User Info"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Does user_id exist?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (get_userdata($user_id) === False)\n  {\n    \/\/user id does not exist\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get User ID<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (is_user_logged_in())\n    $user_id = get_current_user_id();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get username<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/For the current user\n  $current_user = wp_get_current_user();\n  $username = $current_user-&gt;user_login;\n\n  \/\/For a different user\n  $selected_user = get_userdata($UserId);\n  $user_login = $selected_user-&gt;user_login;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get Avatar<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">HTML ready code to display it<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>$AvatarHtml = get_avatar($UserId, 32);  \/\/2nd argument is optional size<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Avatar URL<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>$AvatarUrl = get_avatar_url($UserId);<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Does user_id exist? Get User ID Get username Get Avatar HTML ready code to display it Avatar URL<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[],"class_list":["post-2002","post","type-post","status-publish","format-standard","hentry","category-users"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2002"}],"version-history":[{"count":8,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2002\/revisions"}],"predecessor-version":[{"id":5291,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2002\/revisions\/5291"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}