WordPress stores user_name of logged in user in auth cookie. Auth cookie is signed, so it’s easy to check if it’s fake, so you can trust this info.
OK, so how to get user’s user_name from cookie?
There is function for that 😉
and this is what it returns:
return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' );
So you can use something like this:
$cookie = wp_parse_auth_cookie( '', 'logged_in' );
$user_name = $cookie['username']
to get user_name of user that is currently logged in.
If you need he’s ID and not user_name, then use DB to retrieve it or change content of the auth cookie (here’s how: Removing username from the ‘wordpress_logged_in’ cookie).
Related Posts:
- W3 total cache – cache refresh programmatically [closed]
- Should I use Transient API to store HTML String, or Object?
- Caching: APC vs APCu vs OPcache
- Pros and Cons for high “expire time” on wp-super-cache or w3-total-cache? [closed]
- Limit cache size from W3 Total Cache [closed]
- Does a query executed through wpdb class get cached?
- Configuring WordPress for Amazon CloudFront Caching?
- Caching: Force fresh content for logged-in users (potentially by adding a query variable to the URL)
- Will I see a performance hit if I use native API calls like get_the_title() instead of $post->post_title?
- WordPress Browser Cache with W3-Total-Cache doesn’t show new posts [closed]
- Nginx + WordPress + HHVM: Why isn’t Batcache working? Would Varnish help even more?
- Does a low traffic WordPress site need a caching plugin and a CDN
- Automatically Refresh WordPress Stylesheet
- How to use cache with simplepie
- Fragment caching increasing database queries
- Can I force get_option to go back to the DB instead of cache?
- Settings to get the most out of W3 Total Cache
- How to force content refresh of a page that has been loaded previously by the user? [closed]
- Help Pinpointing Source of Caching Issue
- How to clear cache without a plugin [closed]
- Can someone explain WordPress caching, and what’s the best in my scenario?
- Transient / object cache maximum key length [duplicate]
- APC object caching in combination Batcache/memcached page caching?
- Should the page cache be refreshed often? [closed]
- Plugin a specific cache functionality?
- What is difference between ‘Page Cache’ and ‘Object Cache’ in WordPress?
- Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]
- Getting soft 404 errors (200 status) when caching plugins are enabled
- How to totally disable cache in WordPress?
- Database Cache and Object Cache Difference?
- How to purge all transient caches?
- When use a cache system with WordPress
- Method to make definitively static an abandoned WP blog
- How do I fetch feed info from cache instead of directly from feed?
- pass-protected pages and posts not protected after enter them 1 time
- Static HTML page caching for large website [closed]
- WordPress caching issue
- WP Super Cache Bug with Ubermenu
- Problem with caching, W3TC [closed]
- How to find time last viewed?
- WP Rocket Cache Lifespan – Never clear cache? [closed]
- Disable feed cache for custom RSS feed?
- How do I enable dynamic content in a theme cached with WP Super Cache?
- How to cache a different page version based on HTTP header?
- Live website is not showing the changes I’ve made [closed]
- After having installed APC Object Cache Backend transients stopped working
- WebHostingBuzz cache statement
- Are get_bloginfo queries cached to start, or should they be cached?
- W3 Total Cache can’t create files [closed]
- Files cached as CSS or PHP?
- Is it duplicated if I cache an object that uses data from postmeta?
- How to clear user’s browser cache after publishing a new post?
- A bunch of unrelated wordpress using same memcached don’t store correctly their datas
- Combile External JS files using W3 Total Cache [closed]
- RSS: fetch_feed caching with different caching delay per feed?
- How to be sure to get last page version without ANY cache?
- Is there a limit to size of data stored in update_option()?
- How can I cache font files on WordPress [closed]
- W3 total – leverage browser caching not working with cdn delivered images [closed]
- Browser cache for dynamic content (list of tags)
- How to specify expiration of cacheable resources? [closed]
- Scheduling doesn’t work due to caching?
- APC fragmention woes on Apache AWS EC2 Small instance with WordPress and W3TC [closed]
- w3 total cache – Object Caching 2165/2469 objects? [closed]
- Website working fine when logged in but not working fine when we logged out
- Changing WP Object Caching during runtime
- Best practices for the cache of a static WordPress site, including CDN Cache and Cache Plugin
- Site’s first loading on a new browser with no cache is messed up
- Site speed slows when user logged in
- WordPress mobile version is not responsive anymore after installing varnish
- Admin area is caching posts in the editor
- WordPress on mobile devices with new data after updating page
- Having issues fixing site speed
- Is there a way to cache WordPress that does not loads core?
- Need to refresh page after each change
- leverage browser caching in wordpress
- WordPress varnish pages printed twice
- Feed cache fallback – A feed could not be found
- WordPress Userroles button getting cached
- FATAL ERROR – white page – no site showing
- How to let users clear their posts cache with WP Super Cache?
- Having 4000 posts, my site is so slow
- GravatarLocalCache Plugin Broken in WordPress 4.2
- Super cache caches mobile pages for desktop
- Should I use transients for these API call results?
- My website resets when accessing the index page
- Debug Performance Issues
- cache reset button and question about deleting cache
- Cleared wp-cache and file is still not updated [closed]
- Bluehost WebHost and performance problems with W3TC [closed]
- get_theme_mod returning cached values regardless of apache restart
- Caching with dynamic content
- Levels of caching and impact on the WordPress web site
- CSS changes not taking effect [closed]
- what is the cache directory for in my theme? (version control it?)
- WP 3.5 caching problem
- Multiple WordPress sites eat up a lot of RAM
- Convert WordPress to static website by using the pages generated by the caching plugin?
- How I define max cache time to Google Fonts installed on my site
- Keeping Objects in Memory