If you’re inside a plugin, WordPress is already loaded. You don’t need to load it yourself.
Inside whatever function needs the user ID, you need to do two things:
- Globalize the user data variable
- Populate the user data variable
Here’s some pseudocode:
function some_function_that_needs_user_info() {
global $current_user;
get_currentuserinfo();
// Now reference $current_user->ID in your code.
}
Related Posts:
- How to check username/password without signing in the user
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- WordPress REST API call generates nonce twice on every call
- Custom user profile, registration, login page with theme
- How to use WP default post list tables in a plugin?
- How to add quick edit and bulk edit fields to users admin section
- Generating User(s) with Settings API
- WordPress admin deleted user details not removed in database. How to delete WordPress Users from Database
- Print WordPress username id inside JavaScript
- Function Get User Object By Username?
- Check if someone is editing a post (this content is currently locked)
- Modify users.php page to create page/post on button clicked
- Subscribe to author?
- How to filter users list on user_status field with get_users()
- Frontend language per user
- Display custom fields in frontside user profile
- global $current_user not current user
- Display list of uploaded images, filtered by user under a specific user group
- How to build a fool proof AdSense revenue sharing model?
- Hide custom post type by user roles
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- How to allow only two (or more) users access to a plugin
- First and last name fields not filled when using wp_insert_user
- Wp-admin Custom User Management
- get author of published post
- How to get custom post_author?
- Associate multiple email addresses with the same user account, so they can log in with either
- Update a user profile via frontend
- Best practice for Designing a Plugin with this scenario
- Adding another field to user table
- how to get the top 10 popular blogs
- How can I change my assigned user role in WordPress 3.5.1?
- How to relate the Category to user?
- Adding a dropdown on the user admin
- Allowing duplicating users with same user_login and user_email
- Why User_login key doesn’t work with wp_update_user()
- How to grab data after wp user search is complete
- How to prevent users from deleting their accounts?
- User Registration Moderate
- How to retrieve custom profile fields associated with different users
- Upgrade routine: Interaction with user confirmation
- Multiple Users Logged In Causing Incorrect Account Returned
- first_name property missing inside register_user action hook
- user can login from single account detail from multiple locations(computer) at the same time [closed]
- Create Unique and Customized User ID for Website Members in WordPress
- WP 3.3 How to Add Menu Items to the Admin Bar?
- Unit tests – Dealing with dependencies
- Changing Plugin Load Order
- Should I create a theme or a plugin?
- How should you hook a session_start() when authoring a plugin?
- How to change wordpress post title?
- How to create a plugin that only operates on the home page?
- Adding callback function for wp_ajax_ has no effect
- How to properly modify get_userdata in plugin to get roles to update in database
- Create a plugin to change the action to which a function is hooked
- Why is the reset password key missing in the reset password email?
- Paging on a future post loop?
- How to pass custom options from widget form to widget update callback?
- How can I add a field to make link nofollow to the WordPress Link Inspector Window?
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- How to show large image in checkout page using WP Ecommerce plugin [closed]
- Why do I need to check if wp_nonce_field() exists before using it
- settings_fields() doesn’t work for other roles except admin
- edit_{$taxonomy} | Hook
- how to make custom bulk actions for a WP_List_Table (core class)
- Get name and email of current unregistered user, who has recently submitted name and email in comment form?
- How to associate an existing user to a site in a multisite setup programmatically
- Changing upload dir in a plugin regardless of post type
- Auto save permalink setting page with the plugin activation
- creating custom function to log actions in plugin
- Howto: Use Custom Post Types as Submenu Items in Admin
- Show custom data instead of 404
- What’s the right way to instantiate new blocks and/or the plugin itself in toto when using wppb architecture?
- How can I get a list of CPT inside a plugin file?
- Creating a custom Gutenberg block with columns
- Serve text/html from wp-json API via WPEngine, headers not being set properly
- Add a new confirmation page before saving
- How to handle shortcodes through plugin
- WordPress debug messages not displaying
- Show message from backend
- PHP File_exist() not working – Checking if File Exist in WordPress Theme Directory
- Woocommerce inventory [closed]
- Add a check box in Menu Settings
- Is there any way to fire heartbeat API from for website visitors?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- How can I prevent ‘500 internal server error’ because of a long install process?
- Displaying custom content from a plugin within the active theme
- Custom plugin & calling REST api of wordpress instance the plugins is running on
- Add variables from rewrite rules to query var
- How do I specify where to save the debug.log?
- Code for cron to delete posts that contain specific expression (e.g. “unable to fetch” every 30 minutes
- How to fetch the post content from the wordpress editor before it can be saved(published)?
- pull data from wordpress database
- How does one set cookies in WordPress without getting the ‘headers not sent’ error? within WP
- Glyphicons Dont Show in WordPress Plugin Only
- Change the search results header from plugin
- Add query string variables to all hyperlinks URL matching a specified domain
- Virtual Page with Registration form
- Is there such a thing as a WordPress console?