Instead of using init
hook why don’t you use the wp_loaded
hook. This way, you’re sure that everything is loaded
add_action('wp_loaded','do_stuff');
function do_stuff(){
$current_user = wp_get_current_user();
if ($current_user->ID > 0) {
// rest of your code here
// $current_user->ID will give you the ID of the current user.
}
}
Related Posts:
- How do I create a custom role capability?
- Custom user profile, registration, login page with theme
- Why is the reset password key missing in the reset password email?
- How to get the ID of the currently logged in user?
- Check if someone is editing a post (this content is currently locked)
- How to restrict access to image folder depending on whether product is purchased or not?
- How can I create a custom plugin that allows anonymous users to signup without registering?
- User Data Handling between two plugins
- How do I control the list of Pages an author can see?
- How to include PHP files in plugins the correct way
- Checking if a file is already in the Media Library
- Prevent network activation of plugin
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Get list of scripts / styles and show file which enqueued them
- WordPress updates defined vs add_filter?
- How can I track active users of my plugin? and why doesn’t WordPress.Org offer this?
- Empty POST data on server on AJAX request using Angular $http
- Custom attachments uploader code. Almost there!
- $wpdb->insert is changing a value
- What are the default WordPress password requirements?
- Can I get all options using the option group id? [closed]
- Actions or filters fired when data is saved in a custom table
- Implementing namespaces in plugin template
- Conditional add_filter?
- The plugin generated 80 characters of unexpected output!
- How to update/auto-update my private plugin? [duplicate]
- How to use WP default post list tables in a plugin?
- What’s the Right Way to get and save remote data for a Gutenberg block?
- Commit changes to WordPress Plugin SVN with TortoiseSVN
- Passing array of strings to a SQL statement in a WordPress plugin
- Add multiple shipping rates from add_rate function with custom ID
- add_shortcode is not working [duplicate]
- Filter, or any way to dynamically change theme screenshot image?
- On Plugin Activation, How Do I Check for Proper Transport Mechanism?
- Show add_meta_box by selecting a specific category
- Can a plugin be used to contain all custom functions to extend other plugins
- How to render a time-of-day string like ’16:42′ with a site’s chosen time format?
- Are block templates incompatible with serialize_blocks?
- ServerSideRender and Media Object: attributes passing image data object to php renderer even though it’s not set
- Programmatically modify an admin page UI of a WordPress site from my WordPress plugin
- Check Paypal Purchase is Success or Not in Easy Digital Download Plugin
- Render content after post title in wp-admin
- Error on inserting a form value to database
- Wp_list_table search box not working for custom value from database
- Notice: Trying to get property ‘term_id’ of non-object
- Append wp_editor to Dynamically created textarea
- javascript datatables in a plugin
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- How to change the column label in screen options for a custom column?
- include php file if page_id matches
- captcha not working in my custom plugin
- Selectively update themes in WordPress multisite
- Optimising a big WordPress site
- How do I link to a php file in my plugin directory?
- Is it possible to abort post update if specific conditions on metadata are met?
- Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
- How to create a page with a form programmatically in WP?
- jQuery instantly executes (a button click and css change) on load
- Category select options for plugin settings
- why do I have to use required parametres?
- How to make my shortcode load scripts and styles, from within the plugin?
- Class cannot be found, but it’s available in the file, I get: Fatal Error: Uncaught Error: Class ‘Blocks\Base\Activation’ not found
- how to change image of jquery slider plugin
- Enqueueing common php scripts in a plugin
- plugin content on front-page only. Nowhere else
- get_avatar filter in WordPress 4.4, how to filter properly
- How to use a WP_Customize_Control outside of the Customizer?
- How can I save a password securely as a settings field
- How to make a cronjob type plugin
- Update plugin settings option_name for big plugin update
- Changing permalink structure breaks link to .php file which generates files dynamically
- Decontruct serialized data array from wp_options
- Simulating timeout is not working
- $wpbd->insert_id is returning null
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- Plugin Activation Causes wp_register errors
- BuddyPress and namespacing
- How to get values from Tinymce visual editor popup?
- How to debug new shortcode? And how to get string from shortcode into code?
- Ajax call not working with
- plugin modal/popup integration best practice
- how to display my WordPress plugin on a chosen page?
- Issue with iframe in TinyMCE
- Sessions in plugin development?
- List all content by post type
- Best Way to Grab Post ID from Plugin
- How to set/change another post author by custom fields or something else?
- Fatal error: Call to a member function query() on a non-object in my ajaxpage
- Loop output for custom plugin [solution found]
- How to Pass ID through Short Code
- Gutenberg’s Popover component position relative to the focused element
- How to replace plugin icon?
- How to change the headline title for an admin page in a plugin?
- Cannot update plugin
- PHPUnit Testing Installation Issue
- Loading all PHP files all the time or only when they needed in Custom Plugin Development [closed]
- Showing Home option in dropdown when there is no Home page exist
- How to customize password reset message page on success if no error in password reset
- Do uploaded files to /tmp/ get deleted in WordPress automatically?
- How to pass a user_id to a custom plugin