Contents
How can I find the ID of a WordPress User?
This is a very simple method, but it also have some disadvantages. First – you should be logged in, second – you can not obtain the id of your own user. So: Log into your WordPress admin. Go to Users > All users. Choose the user and go to his profile.
(string) (Optional) The user field to retrieve. (int|false) (Optional) User ID. (string) The author’s field from the current author’s DB object, otherwise an empty string. If used within The Loop, the user ID need not be specified, it defaults to current post author.
When to use get the author meta ( ) in PHP?
If used within The Loop, the user ID need not be specified, it defaults to current post author. A user ID must be specified if used outside The Loop. get_the_author_meta () returns the data for use programmatically in PHP.
How to get the CURRENT USER ID in PHP?
The easiest way to get the current logged in user ID with PHP is to use the get_current_user_id () function. This is the ideal solution if you’re building custom code and need the current user’s ID. If you’d like to get a WordPress user’s ID by an email address here is how you do that using the get_user_by () function.
How to call WP _ get _ current _ user ( ) in a plugin?
To add to @EAMann’s answer, you need to wrap your wp_get_current_user () call (or any call that tries to access a function defined within pluggable.php) within the ‘plugins_loaded’ action. So, if you’re putting this inside your functions.php file, do it like this:
How to get current logged in user using WordPress REST API?
If you prefer use JWT Authentication for WP REST API, it may be easier to implement with Json Web Tokens. First you authenticate the client sending a HTTP POST request to the endpoint /wp-json/jwt-auth/v1/token sending username and password fields to generate a auth token.