{"id":35172,"date":"2022-03-02T15:00:13","date_gmt":"2022-03-02T14:00:13","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=35172"},"modified":"2022-03-21T09:10:46","modified_gmt":"2022-03-21T08:10:46","slug":"how-to-retrieve-logged-in-wordpress-users-info","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/how-to-retrieve-logged-in-wordpress-users-info\/","title":{"rendered":"How to Retrieve a Logged-in WordPress User\u2019s Info"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]The logged-in WordPress user info can be used in various ways: as part of authentication processes for a plethora of web applications, in specialized plugin dashboards or options screens, as part of the default WordPress interface, and many others.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]While most of these features and functionalities are<strong> often part of WordPress plugins<\/strong>, both free and premium, some can also be achieved with custom code. Knowing how to retrieve the info of logged-in WordPress users can help you implement those customizations, given sufficient coding knowledge and skill.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The topic that we are going to cover in this article is a bit <strong>more coding-focused<\/strong>. And, while the examples that we prepared for the article aren\u2019t that difficult, they still require a great deal of coding and general WordPress knowledge to be understood and implemented properly. Thus, we must put a disclaimer that<strong> the article is intended for intermediate and advanced WordPress users<\/strong> before going any further.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]In this article, we will show how you can <strong>display the info of logged-in users, add personalized welcome messages, and a way to track the date and time of their last login<\/strong> on the website using snippets we created for this article. To use them on your website, you will have to include them, via FTP, either in the functions.php file of your child theme or a <a href=\"https:\/\/qodeinteractive.com\/magazine\/wordpress-site-specific-plugin\/\">site-specific plugin<\/a>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To users less familiar with the FTP process, we advise consulting our article on <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-use-ftp\/\">how to use FTP<\/a> beforehand. Additionally, as a safety precaution, we strongly advise you to make <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-manually-backup-wordpress-website\/\">a backup of your website<\/a> before adding the code. This is what we will be covering:[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#retrieving-basic-user-info\">Retrieving Basic User Info<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#wordpress-hooks-and-displaying-user-info\">WordPress Hooks and Displaying User Info<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#displaying-personalized-user-messages\">Displaying Personalized User Messages<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#adding-and-displaying-new-info\">Adding and Displaying New Info \u2013 User\u2019s Last Login<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;80px&#8221;][vc_widget_sidebar sidebar_id=&#8221;new-top-picks-banner&#8221;][vc_empty_space height=&#8221;80px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"retrieving-basic-user-info\"><\/a>Displaying Basic User Info<\/h2>\n<p>[\/vc_column_text][vc_column_text]One way of retrieving and displaying the currently logged-in user info involves using the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_get_current_user\/\" target=\"_blank\" rel=\"noopener\">wp_get_current user()<\/a> function. Specifically, <strong>this function retrieves the current user object<\/strong>, which you can then use to display its relevant properties or perform some other actions. We have included a simple coding snippet showing how you can <strong>retrieve that info and show some of the user properties<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function qode_get_current_user_info() {\r\n$current_user = wp_get_current_user();\r\nif ( ! ( $current_user instanceof WP_User ) ) {\r\nreturn;\r\n}\r\necho sprintf( __( 'Username: %s,&lt;br \/&gt;', 'textdomain' ), esc_html( $current_user-&gt;user_login ) );\r\necho sprintf( __( 'User email: %s,&lt;br \/&gt;', 'textdomain' ), sanitize_email( $current_user-&gt;user_email ) );\r\necho sprintf( __( 'User first name: %s,&lt;br \/&gt;', 'textdomain' ), esc_html( $current_user-&gt;user_firstname ) );\r\necho sprintf( __( 'User last name: %s,&lt;br \/&gt;', 'textdomain' ), esc_html( $current_user-&gt;user_lastname ) );\r\necho sprintf( __( 'User display name: %s,&lt;br \/&gt;', 'textdomain' ), esc_html( $current_user-&gt;display_name ) );\r\necho sprintf( __( 'User ID: %s', 'textdomain' ), esc_html( $current_user-&gt;ID ) );\r\n}<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Let us elaborate on the code a bit.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]This code snippet represents a custom function called <strong>qode_get_current_user_info()<\/strong>. In it, we have first stored the instance of the current user inside the <strong>$current_user<\/strong> variable using the <strong>wp_get_current_user() function<\/strong>. For added safety, we have added a conditional statement which checks whether the previous action was performed successfully. Then, <strong>the remaining part of our custom function prints out the info for that user<\/strong> \u2013 their username, email, first name, last name, display name, and ID.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]As previously mentioned, if you want to use this custom function, <strong>you will need to insert the coding snippet via FTP either into the<em> functions.php<\/em> file of your child theme or a site-specific plugin<\/strong>. However, even after doing so, you won\u2019t be able to see the specified info of the currently logged-in user. The reason for it is that functions need to be executed to work properly.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]As <strong>our snippet lacks the one line of code which executes it,<\/strong> nothing will happen after adding the previous coding snippet into one of the two suggested locations. You need to add the missing line of code which calls, i.e. executes the function. However, this is a far more complex task than one might imagine as it involves understanding and using WordPress hooks.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"wordpress-hooks-and-displaying-user-info\"><\/a>WordPress Hooks and Displaying User Info<\/h2>\n<p>[\/vc_column_text][vc_column_text]Simply put, WordPress hooks are<strong> pieces of code which act as a placeholder<\/strong>, allowing other developers or WordPress users to add new functionalities to their WordPress website or to change existing ones. More precisely, we distinguish two types of WordPress hooks. These are <strong>action hooks<\/strong>, used for adding new features and functionalities, and <strong>filter hooks<\/strong>, used for changing existing ones.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Users need to create <strong>custom functions called callback functions or callbacks<\/strong> which are \u201chooked onto\u201d those placeholders. In that sense, the callbacks are what defines a custom functionality, while the \u201chooking onto\u201d aspect is what ensures that the callback\u2019s code is executed, i.e. that the functionality is enabled.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Furthermore, <strong>by hooking your callback(s) onto a hook you ensure that the custom code is executed<\/strong> at the exact place where the hook is located. This means that you won\u2019t have to change existing template files to add new functionalities or change existing ones, which was common practice in earlier years of WordPress. Instead, using WordPress hooks, <strong>you can keep all your modifications in one place<\/strong>, either the <em>functions.php<\/em> file of your child theme or a site-specific plugin, as previously mentioned. And not only that: <strong>you won\u2019t have to worry that your modifications will get overridden<\/strong> after each WordPress, theme, or plugin update.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]That said, the \u201chooking onto\u201d part requires a line of code \u2013 the use of the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_action\/\" target=\"_blank\" rel=\"noopener\">add_action()<\/a> function for action hooks and <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_filter\/\" target=\"_blank\" rel=\"noopener\">add_filter()<\/a> for filter hooks. Both of these functions accept four arguments. These are the following: the hook you want to \u201chook onto\u201d, the callback function being hooked, the priority of the callback function in the order of callback function execution, and the number of arguments the callback function accepts.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The default priority is set to 10, while the default number of arguments of the callback function is set to 1. Therefore, in most cases, only the first two arguments can be used, while the default values for the other two are used implicitly. Of the first two, the hook is the more important one, as it determines the placement of the code. It is the choice of which hook to use that makes this method of adding customization to a WordPress website so developer-friendly, as it is done on a case-by-case basis.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Depending on the customization you wish to add, there could be many suitable hooks as a part of the WordPress core files or placed within the template files of your theme and plugins. However, knowing them requires in-depth knowledge of WordPress code, as well as of the code behind your themes and plugins. Therefore, for those not familiar with WordPress code, we strongly suggest consulting your theme or plugin authors to find the most suitable hook to implement the customization you had in mind.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Having explained that, let us return to the custom function we mentioned in the previous section \u2013 <strong>qode_get_current_user_info()<\/strong>. As it displays the info only without altering any of the data, that means you should hook it onto a suitable action hook. Thus, you would use the following line of code to execute the function:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">add_action('suitable-action-hook-here','qode_get_current_user_info');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]with the <em>suitable-action-hook-here<\/em> part properly replaced with a suitable action hook.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"displaying-personalized-user-messages\"><\/a>Displaying Personalized User Messages<\/h2>\n<p>[\/vc_column_text][vc_column_text]One simple yet effective feature you can implement on your website is to <strong>add personalized user messages<\/strong>. This can help you create and strengthen bonds with your users. While there are a lot of various types of messages, as an example, we will show how to <strong>create a unique welcome message for your logged-in users<\/strong> while showing a more generalized version of that message to non-logged-in visitors of the website. The snippet we created specifically for this article is given below.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function qode_welcome_message() {\r\nif ( is_user_logged_in() ) {\r\n$current_user = wp_get_current_user();\r\necho '&lt;h1 class=\"qodef-welcome-title logged-in\"&gt;' . sprintf( esc_html__( 'Welcome to the website, %s', 'textdomain' ), empty( $current_user-&gt;user_firstname ) ? $current_user-&gt;display_name : $current_user-&gt;user_firstname ) . \"&lt;\/h1&gt;\";\r\n} else {\r\necho '&lt;h1 class=\"qodef-welcome-title\"&gt;' . esc_html__( 'Welcome to the website', 'textdomain' ) . '&lt;\/h1&gt;';\r\n}\r\n}<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]It represents a custom function called <strong>qode_welcome_message()<\/strong>. It is a simple coding snippet that uses the <a href=\"https:\/\/www.php.net\/manual\/en\/control-structures.elseif.php\" target=\"_blank\" rel=\"noopener\">if \u2026 else \u2026<\/a> conditional to display two versions of a welcome message. By using the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/is_user_logged_in\/\" target=\"_blank\" rel=\"noopener\">is_user_logged_in()<\/a> function we have checked if the current website visitor is logged in and, if they are, displayed a welcome message with their first name at the end. In the case the visitor\u2019s first name doesn\u2019t exist, their display name is shown instead. On the other hand, if the visitor isn\u2019t logged in, a generic welcome message is shown. This is a very simple way of adding personalization to your website which your logged-in users might appreciate.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]However, similar to our first coding snippet,<strong> you will need to hook the custom function onto a suitable hook<\/strong> for the code to be executed and display its result on your website. As our custom function doesn\u2019t alter any arguments, it should be hooked onto an action hook. The line of code you need is the following:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">add_action( 'suitable-action-hook-here, 'qode_welcome_message' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]with the<em> suitable-action-hook-here<\/em> part properly replaced.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"adding-and-displaying-new-info\"><\/a>Adding and Displaying New Info \u2013 User\u2019s Last Login<\/h2>\n<p>[\/vc_column_text][vc_column_text]As another example, we will show you how to<strong> assign additional properties to your users, add relevant data and display it in the website\u2019s backend<\/strong>. For this purpose, we will show how you can extend the Users &gt; All Users section to display the last login date and time for all users that are registered on the website. This will help you track the changes your administrators, editors, authors, and contributors have made to the website, in case some need to be reverted or if some suspicious activities occur during the time they are logged in.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Even though not present by default in WordPress, in this day and age, such a feature is <strong>very important for your website\u2019s security<\/strong>. And, while we have already created a separate article on how you can display <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-show-users-last-login-date-in-wordpress\/\">the user\u2019s last login date<\/a>, we have decided to include this example that offers a slightly different take on the subject. The custom coding snippet you need is below.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function qode_add_user_last_login( $columns ) {\r\nforeach( $columns as $key =&gt; $value ) {\r\n$columns['last_login'] = esc_html__( 'Last login', 'textdomain' );\r\n}\r\nreturn $columns;\r\n}\r\nadd_filter( 'manage_users_columns', 'qode_add_user_last_login' );\r\nfunction qode_update_user_last_login( $user_login, $user ) {\r\nupdate_user_meta( $user-&gt;ID, 'last_login', time() + 3600 );\r\n}\r\nadd_action( 'wp_login', 'qode_update_user_last_login', 10, 2 );\r\nfunction qode_display_user_last_login( $value, $column_name, $user_id ) {\r\nif ( $column_name !== 'last_login' ) {\r\nreturn $value;\r\n}\r\n$last_login_timestamp = get_user_meta( $user_id, 'last_login', true );\r\nif ( ! $last_login_timestamp ) {\r\nreturn '\/';\r\n}\r\nreturn date( get_option('date_format') . ' ' . get_option('time_format'), (int) $last_login_timestamp );\r\n}\r\nadd_filter( 'manage_users_custom_column', 'qode_display_user_last_login' , 10, 3 );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]This coding snippet is more complicated than the previous two, as it consists of three separate functions which are hooked onto corresponding action and filter hooks. Therefore, to properly elaborate on the code, we will try to explain the functions one at a time.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The first function is called<strong> qode_add_user_last_login()<\/strong> and it adds a new column to the Users &gt; All Users screen. That new column is called \u201cLast login\u201d, added using a <a href=\"https:\/\/www.php.net\/manual\/en\/control-structures.foreach.php\" target=\"_blank\" rel=\"noopener\">foreach<\/a> cycle. Of course, for the code to execute properly, we would need to hook our functions onto a suitable hook. In this case, that was the manage_users_columns filter hook. This hook is a part of a larger, dynamic filter hook \u2013 <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/manage_screen-id_columns\/\" target=\"_blank\" rel=\"noopener\">manage_{$screen-&gt;id}_columns<\/a> which filters a list of headers for the list table on a specific screen.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function qode_add_user_last_login( $columns ) {\r\nforeach( $columns as $key =&gt; $value ) {\r\n$columns['last_login'] = esc_html__( 'Last login', 'textdomain' );\r\n}\r\nreturn $columns;\r\n}\r\nadd_filter( 'manage_users_columns', 'qode_add_user_last_login' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The second function is called <strong>qode_user_last_login()<\/strong> and it updates the user\u2019s last login time in the database using the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/update_user_meta\/\" target=\"_blank\" rel=\"noopener\">update_user_meta()<\/a> function. Even though this might seem quite self-explanatory, the parameters that we used warrant a bit of elaboration. First, we have made sure that the column that is updated is the one denoted by the <strong>last_login<\/strong> key, which we previously used while creating the Last login column. Then, the user whose last login is tracked is uniquely determined using his ID. Finally, the user\u2019s last login is calculated using the <a href=\"https:\/\/www.php.net\/manual\/en\/function.time.php\" target=\"_blank\" rel=\"noopener\">time()<\/a> function. This function returns a timestamp which represents the number of seconds since the Unix Epoch (January 1, 1970, 00:00:00 GMT) with regards to the UTC timezone. As the timezone we have selected on our website is UTC+1, we have added an extra 3600 seconds (1 hour) to offset this difference.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function qode_update_user_last_login( $user_login, $user ) {\r\nupdate_user_meta( $user-&gt;ID, 'last_login', time() + 3600 );\r\n}\r\nadd_action( 'wp_login', 'qode_update_user_last_login', 10, 2 );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Finally, the third function, called <strong>qode_display_user_last_login()<\/strong>, is responsible for displaying a user\u2019s last login time in a more human-readable format than one provided by the time() function. More precisely, the last login timestamp is acquired using the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_user_meta\/\" target=\"_blank\" rel=\"noopener\">get_user_meta()<\/a> function. Then, depending on whether the timestamp exists for a given user, two outcomes are specified. Firstly, if a given user has no last login timestamp, a simple slash will be shown in the Last login column next to the respective user. On the other hand, if the last login timestamp exists within the database, it will be displayed in the Last login column in a more human-readable format using the date() function.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]As for the format that we have used, it relies on the Date Format and Time Format options which can be set up in the Settings &gt; General section. Additionally, we will say we haven\u2019t altered the values for any other columns. Nevertheless, as we have undeniably changed the default view of the Users &gt; All Users screen, we had to hook the function onto a suitable filter hook, which was <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/manage_users_custom_column\/\" target=\"_blank\" rel=\"noopener\">manage_users_custom_column<\/a>, in this case. Of course, the reason for it is that this filter hook is the hook responsible for what is displayed in the custom column we previously created.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function qode_display_user_last_login( $value, $column_name, $user_id ) {\r\nif ( $column_name !== 'last_login' ) {\r\nreturn $value;\r\n}\r\n$last_login_timestamp = get_user_meta( $user_id, 'last_login', true );\r\nif ( ! $last_login_timestamp ) {\r\nreturn '\/';\r\n}\r\nreturn date( get_option('date_format') . ' ' . get_option('time_format'), (int) $last_login_timestamp );\r\n}\r\nadd_filter( 'manage_users_custom_column', 'qode_display_user_last_login' , 10, 3 );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]This concludes the explanation of our third coding example. However, we must add one last remark before showing the result. Since this coding snippet adds a property to any user \u2013 the timestamp of his last login \u2013 this property can also be displayed using the first coding snippet we mentioned in this article. Specifically, you can edit the snippet shown in the section on <a href=\"#retrieving-basic-user-info\">displaying basic user info<\/a> and display the last_login property of the current user. However, you would have to use the date() function or any similar function that converts the last_login timestamp into a more readable format, as we did near the end of the<strong> qode_display_user_last_login()<\/strong> function above.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Having said that, the only thing that remains is to examine the result of our coding. As we have specified all the hooks for this example,<strong> the code will be executed and the result displayed on the website<\/strong>. In this case, this is <strong>in the website\u2019s backend, in the Users &gt; All Users section<\/strong>. We have included a screenshot of the result on our end below.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/All-Users.jpg\" class=\"attachment-full size-full\" alt=\"All Users\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/All-Users.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/All-Users-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/All-Users-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/All-Users-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;60px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/User-Last-Login.jpg\" class=\"attachment-full size-full\" alt=\"User Last Login\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/User-Last-Login.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/User-Last-Login-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/User-Last-Login-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2022\/03\/User-Last-Login-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;78px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Final Thoughts<\/h2>\n<p>[\/vc_column_text][vc_column_text]Knowing how to retrieve the info of logged-in WordPress users can help you implement modifications to your website which make the interaction with them a bit more personalized or add features which can improve your website\u2019s security, among other things. In this article, we have explained the ways to display the info of logged-in users, make customized welcome messages, and a way to track the date and time when your users last logged into the website.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]While these examples are quite simple in comparison to what can actually be achieved with advanced coding skills, they have been thoroughly explained so as to be clear to intermediate and advanced WordPress users. Therefore, we are sure you will be able to implement them on your end, and even create additional website modifications with the logged-in WordPress user\u2019s info you retrieved thanks to methods described in this article.<br \/>\n[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Retrieve WordPress user info and use it to personalize your website, track your logged in users, and more.  <\/p>\n","protected":false},"author":11229,"featured_media":35187,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[222,4,13],"class_list":["post-35172","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-admin","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/35172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/11229"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=35172"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/35172\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/35187"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=35172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=35172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=35172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}