The problem with your code is that you want to get current user to early.
wp_get_current_user
is using global current_user
variable.
But this variable isn’t set from the beginning.
And if you want to use this function straight in the script file, then it’s to early.
You should wait for init
action to get current user.
require($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
add_action( 'init', function() {
$current_user = wp_get_current_user();
var_dump($current_user->ID);
var_dump($current_user->display_name);
});
Related Posts:
- add_user_meta() vs update_user_meta()
- Get basic Image Uploader on User Profile Page
- Return all users with a specific meta key
- Capabilities Vs User Meta
- Problem storing arrays with update_user_meta
- wp_get_current_user always returns 0
- get_users is expecting unserialized meta_value
- how to get specific fields from get_user_meta()
- Validating a new user registration field
- Check if WP_User_Query ‘include’ is empty
- User meta to post
- Add profile field (usermeta) to Add New User
- How to Make admin Sidebar Menu always be Collapse by code
- How to query users by meta value, even when meta key doesn’t exist?
- Add a member number to new user
- Hook or action to save profile fields at specific time
- How to get the user description with get_users?
- get current user not working
- Multiple User-Meta Values in One User-Meta Key
- No first_name or user_firstname property in WP_User object
- Possible bug: update_user_meta is updating two unique meta entries
- Update user meta through a front end form
- How to display current_user bio
- Is a user_meta research case-sensitive or not
- Store user’s registration date as meta
- Can I prevent “wp_user_level” from getting added to wp_usermeta on registration?
- How to tell whether a user meta value has increased or decreased [closed]
- Send mail to user only once when specific check box is selected and updated from profile meta updated by admin
- WP_user_query throws a 404 error
- Incrementally add or substract from usermeta field
- Why get_users() not working on the admin backend?
- Can I set user meta for theoretical user 0?
- strange issue with user_meta + json_encode/decode
- Inserting and finding multiple values in user-meta fields
- Update user meta on logout
- Adding user data to an existing user_id
- I want to update my user meta table
- Problem to wp_hash
- action user_new_form param is a string
- Redirecting users based on custom user meta
- Customize Avatar using user meta
- get_user_meta returning old data
- Why does the usermeta table contain html entities?
- How can I programmatically show a specific (template) page, like author.php?
- WP_User_Query not returning users with meta – what am I missing?
- Randomize Users
- Fetch user related data
- “Select your country” landing page. Remember user choice
- How get meta from all users?
- Order By Meta_key but convert custom date to Y-m-d first
- Update user meta without lose of old data
- Using xprofile_insert_field
- Test if key is in user_meta array
- Combining wp_list_authors with get_user_meta
- Using WP for user management
- Show extra user profile meta for current user
- Pulling member name from WordPress URL
- Add additional Fields for users and get value
- Remove fields from WordPress profile
- E-mail Update – Validation
- How to save a label for an extra user meta field and to display it later?
- Display user meta data from a textarea as a formated text
- gform_after_submission not working as expected [closed]
- Remove user id’s stored in arrays that themselves are stored in user meta of another user
- Sort users by meta key value even if meta key not present for all users
- Wrong result in fetching User meta of WordPress
- Fetch user’s using Last Name
- How to display user_meta array as a table?
- How can I search user meta by a partial key name?
- how to get users with usermeta include array of an array
- get_user_meta value is stored within strange characters
- Delete user meta ( delete_user_meta ) by key without user id
- Why is my Custom User Meta deleted on Profile Update?
- wp_redirect not working after update_user_meta
- How to remove the url format from the WEBSITE field in the user registry?
- users joined group count in buddypress
- Edit a user profile field on front end
- SQL – Shorter way to query user and usermeta data
- WP author meta disappeared
- How to set a user meta key value based on another user meta key value
- How to get value from radio buttons meta box, and return different contents?
- Changing an array of IDs in the usermeta table to fit different format
- Using wp_login vs login_redirect to redirect based on user-meta
- Saving an array of values (file urls) to update_user_meta()?
- get user role value as a string from wp usermeta table into custom script
- Get currentuserinfo firstname and lastname
- Create a dropdown list displaying users meta data
- Get meta value and associated user meta
- Store Foreach in user profile
- use single form to enter multiple profiles
- Allow users to create and store data and retrieve it on login
- How to access User meta data within a plugin
- Using IDX feed to display agent’s and listings with agent’s info associated for Real Estate Website
- user profile replace first name last name with custom values
- Custom user meta data [closed]
- WPML – how to translate user profile fields with icl_t()? [closed]
- Creating a Digital Download facility and track downloads [closed]
- Find matches of a variable in custom usermeta
- get user id from custom user meta key
- Can’t display user bio