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
- Best way to show Dynamic Content on a Cached WordPress Site?
- Is define(‘WP_CACHE’, true) needed for object caching?
- Prevent WordPress from sending Cache-control http header
- Optimize apache for WP use
- 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)
- Multiple WordPress sites eat up alot of RAM
- What exactly is an advanced object cache?
- Using a wildcard with delete_transient()
- 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
- wp_cache_set() or wp_cache_add()
- 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?
- Which WordPress pages/URLs should never be cached?
- How to archive a wordpress site (make it read only)
- How to purge all transient caches?
- Stale cache handling with a persistent object cache
- Varnish + W3 Total Page Cache [closed]
- Are there any server requirements for WordPress transients to work properly?
- Writing a cache manifest file for a WordPress blog (app cache, offline web applications)
- W3 Total Cache doesn’t detect memcached [closed]
- 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’t see live version of style.css – is it web server caching?
- Want to enforce the visitor to load the new version of your stylesheets and scripts [closed]
- Can someone explain WordPress caching, and what’s the best in my scenario?
- Transient / object cache maximum key length [duplicate]
- Speed up WordPress
- wp-super-cache exclude file from caching
- APC object caching in combination Batcache/memcached page caching?
- Should the page cache be refreshed often? [closed]
- WordPress caching in development
- Plugin a specific cache functionality?
- What is difference between ‘Page Cache’ and ‘Object Cache’ in WordPress?
- W3 total Cache – Site with query strings
- Possible to configure nginx to ignore cache for logged in users in certain roles only?
- Should I enable FastCGI on WordPress?
- Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]
- Will caching WordPress affect session variables, custom filed updates and displaying images from a non wordpress table?
- Getting soft 404 errors (200 status) when caching plugins are enabled
- How to totally disable cache in WordPress?
- Automatically enabled caching in some hosting companies w/o visible plugin (Must use plugin)
- Database Cache and Object Cache Difference?
- Register script version not showing
- How to purge all transient caches?
- W3 Total Cache plugin integration
- When use a cache system with WordPress
- server load. $_SERVER[‘REMOTE_ADDR’] and $_SERVER[‘HTTP_HOST’] [closed]
- Optimizing Jetpack for WordPress [closed]
- Is it possible to save an entire piece of rendered HTML in a transient?
- Execute a piece of code also when the cached version of a page is served
- 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
- Can a WordPress blog be entirely hosted on a CDN if cached?
- Static HTML page caching for large website [closed]
- To have WordPress interact with memcached it must be installed as a PHP extension?
- Transients are not expiring as expected in simple custom plugin
- WordPress caching issue
- Prevent installation of style.css cookies and file caching
- How can I revert to showing cached pages when no database connection is available? [closed]
- WP Super Cache Bug with Ubermenu
- How to speed up my site [duplicate]
- Problem with caching, W3TC [closed]
- Headway body classes and W3TC page cache conflict [closed]
- Reasonable Size Limit to options entry
- Is the object cached?
- How to find time last viewed?
- How can I cache the LearnDash quizzes on my server?
- 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?
- WP_Object_Cache for heavy WP_Query
- How to store or cache custom shopping cart data for every user’s session
- Live website is not showing the changes I’ve made [closed]
- How to decode wordpress transient cache stored in database?
- Hook an action when a transient is deleted ? Can’t get it to work!
- WordPress PHP 5.5 and OPcache
- Batcache messages no longer in page source
- After having installed APC Object Cache Backend transients stopped working
- Accelerate and clean up WordPress [closed]
- How to make page/post password protected so you must reenter everytime you visit the page?
- Fixed version number for cached stylesheets and javascript
- WebHostingBuzz cache statement
- Are get_bloginfo queries cached to start, or should they be cached?
- W3 Total Cache can’t create files [closed]