As described in the documentation, you have call this inside a hook.
For wordpress versions < 3.4: use the init or any subsequent action to call this function. Calling it outside of an action can lead to troubles. See #14024 for details.
Example:
add_action('init', 'get_user_email');
function get_user_email() {
$logged_in_user = wp_get_current_user();
if($logged_in_user->ID != 0){
$email = $logged_in_user->user_email;
}
}
Related Posts:
- How do I create a custom role capability?
- Prevent network activation of plugin
- Uninstall script for a plugin in Multisite
- Changing Plugin Load Order
- What is wrong with using add_option with Multisite instead of add_blog_option in a plugin
- How to Get a List of Sub Blogs without Using get_blog_list()?
- Cron firing my function everytime wp-admin is visited
- Error getting correct blog_id on MU from functions.php
- How do I make specific plugin functionality apply to different sites in a network?
- WordPress multisite apply different options over each site from same plugin
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- Multisite, sharing content by URL
- Only allow plugin to be activated on root site of multisite
- How to use wp_set_password in a plugin?
- WordPress Media mime type filter problem 4.0
- What is the best way to overwrite /wp-admin/ms-delete-site.php
- Where should I store global data for my multi-site WordPress plugin?
- unable to stop loop when using wp_insert_post with publish_post hook
- Customize multisite site creation with user data
- Multisite plugin development and wp_enqueue_script
- Plugin Uninstall and Deactivate via Options Menu
- how to activate plugin network-wide, and save setting across sites
- Sharing a common set of image files for media library, across all sites within multisite
- What is difference between blog id and site id?
- How to create a Tools menu on the Network Admin dashboard from a plugin
- Override the default Add/Edit site forms of the Network Panel in custom plugin
- How to set “Site Address (URL)” programmatically on WP multisite?
- How to associate an existing user to a site in a multisite setup programmatically
- WordPress Multisite with Azure B2C redirect_urls after Login
- How To Change Post Author Default?
- Adding (blog-specific) links to “My Sites” admin page
- Plugin menu addition in multisite
- What should happen when a WordPress Plugin is activated across the network (Network Wide Activation)
- Multiple Plugin best practice in Multisite
- Selectively update themes in WordPress multisite
- Problem with context in multisite – getting main site data in every blog (get_pages())
- how to invoke wordpress API from other existing PHP system
- WP Multisite login not working on one subsite. Possibly cookies/ history issue?
- register_activation_hook on multisite
- WordPress multisite,use same cookies across all website?
- WP: Search and replace in DB programmatically
- add_action wp_ajax_ not loading in plugin file WP Network
- Clean way to initialize plugin in newly-added site when plugin has been network activated?
- How to share user data across multiple WordPress websites?
- Is there anything special required to make a plugin work in a multisite environment?
- How to edit wp-signup.php content using plugin
- How do I ensure I can loop through every enqueued script and CSS?
- Custom Plugin activation error in Multisite
- Replace “content-area” of themes 404 page with plugin?
- Multisite and the JSON REST API: How to?
- Testing Plugins for Multisite
- Same header/footer in Admin, across all network sites in multisite
- Change Admin menu placement using hooks
- Force remove parent theme CSS/JS and call them from Child theme
- check if Gutenberg is currently in use
- WordPress Plugin Development – Headers Already Sent Message
- Get page content using slug
- How to include wp-load.php from any location?
- How to disable plugin update notification for a specific plugin in Multisite
- Building a better media uploader for WordPress
- Problems with localization
- Calling clean_term_cache() fails when called in the same plugin that creates terms, succeeds when called separately?
- Singular name Plugin localization
- How to get current page id through the plugin
- How to restrict plugin’s sub-menu pages to admin/subscribers?
- Saving data from block editor to the database
- OOP Plugin and Menu – Call to undefined function register_setting()
- Display content from custom post without modifying the single template
- Loading WordPress Admin Environment
- how to add custom functionality after woocommerce place order button
- Problems with: manage_${post_type}_posts_columns
- Getting timestamp of activation plugin time
- Rich text editor settings persist throughout all rich text editors
- Function: Add link to / inside div
- How can I rewrite a URL to pass requests to a custom method via AJAX? (I can’t use admin-ajax.php)
- WP Gutenberg Blocks – How to limit first/root blocks
- How do I update a field of a meta box?
- How to Get Current Custom Post Type Associated Taxonomy Term
- Are there any official or unofficial guidelines for the styling of a widget?
- How to get error object returned by wp_create_user
- My WordPress Plugin code breaks customize.php viewpoint
- Make wordpress join default user metas with a column from another table while displaying the wp_users table on the users screen
- ajax working when function is on child theme but not in plugin page
- My plugin won’t create table in wordpress 3.5
- Modify custom block plugin without losing content
- How to replace the existing metatag using the backend to insure a thumbnail image gets fetched when we share on social media?
- When setting styles to an extended block that was saved as a pattern, it doesn’t remove the style that was there
- Sanitization and validation input fields – Settings API
- Warning: Illegal string offset ‘Andorra’ in … on line 106
- Different style for specific rows in custom list table using WP_List_Table
- How can I add the Post ID to Class Name in Jquery?
- How to show metabox just in post.php in admin?
- $wpdb how can i save my postmeta table before querying it
- Can’t switch theme after activation
- How do I replace title with my plugin?
- Remove default wordpress roles
- What is the meta_query key name for the woo product average rating? [closed]
- how to catch a data from a array in WordPress
- Why my admin-ajax url returns 0 even after adding echo and die() at the end of function?
- External api call using wordpress