The $current_user
is still a valid global, however like all globals, you should avoid relying on them.
If you need the current user in a function, do this instead:
$current_user = wp_get_current_user();
Also be aware that this may return false if no user is logged in on the current request, while the global $current_user may simply be an invalid instance of the WP_User (with an ID of zero). This is for backwards compatibility, and a wonderful reason to not rely on the globals.
Related Posts:
- How to: inspect global variables in WordPress
- get_post() vs global $post or $GLOBAL[‘post’]
- How to deal with global information without creating a Singleton class
- Using global $post v/s $GLOBALS[‘post’]
- Accessing $post global on a custom post type archive page
- get_query_var vs global query variables?
- What is the global $wp object used for?
- Change global values from templates
- How to avoid repeatedly use the new statement to instantiate a class? [closed]
- Is $page a global variable in wordpress?
- How can i use a global variable in a .css file generated with php?
- Current page id returns the incorrect value
- Echo get_the_category() outside of loop (global?)
- How does WordPress make its functions globally available?
- Recommendations on accessing current user data in WordPress
- WP user agent returns random variables
- How to get particular data from wp_list_comments outside the loop?
- How to save a viewer specific option
- What is the correct way to obtain access to the WP_oEmbed object?
- $GLOBALS[‘value1’] is not working
- Creating a (global)-mapping
- wp localize script makes variable global, how to solve that?
- using globals from wp_link_pages function
- How to set and use global variables? Or why not to use them at all
- Should we trust the post globals?
- What is a good alternative to using $content_width for image optimization?
- When to use global $post and other global variables?
- Where to get information about array fields in $_REQUEST?
- What is the difference between using global $current_screen and get_current_screen()?
- Why declare $post globally?
- Create a global variable for use in all templates
- How to set global variable in functions.php
- Passing variables to templates (alternatives to globalizing variables)
- using 1 form shortcode (si or cf7) for all multisite sites [closed]
- Filter the blog title displayed in the header
- Multisite Installation: how do I setup global search?
- Passing variables to template parts
- Should I global $wpdb outside of any of my plugin’s functions scope?
- How should I store global information such as a phone number so that it is editable through the CMS?
- WP 4.4.1 allow empty comments via add_action ‘pre_comment_on_post’
- Multisite Global Custom Posts
- Adding a section to admin menu for global settings
- WordPress Multisite – global categories
- How to fix a “globals” issue to avoid a rejected theme?
- Global functions on WPMU
- Add classname comment template from functions.php
- What are the disadvantages of using global variable?
- Defining a global array in functions.php?
- Global $post not working in OOP function WordPress
- Call global variable array() in woocommerce child/template
- Override global query results without hooks
- WordPress Loop and $post
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Getting List of all registered Dashboard Widgets
- Create a new query in function.php to filter blog posts
- Relative redirects for posts, categories, products and product categories
- How to access plugin variables from theme templates without using globals?
- Assign External Database Queries to Global Variables and Make Them Accessible
- Declare Global Variable In OOP PHP
- Does WP have a global of $id?
- Test if php document executed by WordPress or directly
- What is the use of $content_width?
- Use global variables or function that returns said variables for site-wide private-ish WP settings?
- WordPress Image Slider Looping Title Not Working
- Declare global var from Template File and use it in Functions.php
- Use a variable created in get_header to calculate stuff in wp_footer
- how to get the post id in plugin
- get_posts() and global variables
- Passing global variable from header.php to functions.php
- Where is this function’s callback getting its arguments from?
- keep a variable for all pages in memory from the url
- Translation issue with global variables
- How to get submenu of admin menu?
- Detecting current page from class method
- Retrieve post in AJAX Callback
- ‘global’ not working in wordpress?
- SFTP define in wp-config.php
- The Global Styles missing
- cannot get global $menu value in form request
- global $product is empty string when passed into function
- Define global custom post
- Custom global variable not working in function
- Hide payment method based on user role AND minimum cart value
- Global $wp_admin_bar always returns null
- How do I get a reference to the HTML memory buffer while the page is being constructed?
- global categories – Share specific categories in wordpress multisite
- Declare global variable that can be used on other function
- Popup panel is only displaying 1 entry ignoring all others
- Best way to access variables in template markup
- Settings in functions.php used by a plugin
- How to set global variable in functions.php
- Current URL path variable
- Save something to global var in add_filter
- key( $GLOBALS[‘wp_registered_sidebars’] ) is always showing the same value
- How do I access variables outside a function [closed]
- WordPress Multisite and site speed and scaleability
- $do_not_duplicate is not working in genesis theme
- Suppress errors when using global function
- Dequeue classic-themes.min.css
- Using global variables