10+
October 27, 2020
March 14, 2019
This plugin sets user cookie when user is logged in.
You can use cookie as data store,
so you can use it as UI resource.
This plugin adds class to html element.
ct-logged-in The current user is logged in.ct-not-logged-in The current user is anonymous.You can control elements visibility with CSS.
.some-element{
display: none;
}
.ct-logged-in .some-element{
display: block;
}
You can use Global Object CookieTasting for utility.
CookieTasting.userName() Returns user name. If not logged in, returns ‘Guest’.CookieTasting.lastUpdated() Returns timestamp of last log in check. If this equals 0, it means that user is anonymous.Besides that, this plugin checks periodically log-in status.
You can handle it with jQuery.
jQuery( document ).on( 'cookie.tasting', function( event, response ) {
if ( response.login ) {
// User is logged in.
// If you use React...
setAttributes({ name: CookieTasting.userName() })
} else {
// User is not logged in.
}
} );
If you use react or something, updated the status with setState().
If you manage cached WordPress and customizing your own theme,
It’s a good idea to implement dynamic UI components with JavaScript.
You can check user’s credential just before important actions.
// Click action for button.
$('.read-more').click( function( e ) {
e.preventDefault();
// Check cookie before do something.
CookieTasting.testBefore().then( function( response ) {
// Now user has fresh information.
// Load premium contents.
loadPremiumContents();
}).catch( function( response ) {
// This user is not logged in.
// Redirect them to login page.
window.locaion.href = '/wp-login.php';
} );
} );
Plese remember adding dependency for cookie-tasting-heartbeat to your script.
By default, this plugin set UUID for each user. This will be…
So you can use it for Google Analytic’s User ID View.
const uuid = CookieTasting.get( 'uuid' ); // For Google Analytics. ga( 'set', "userId", uid );
wp-content/plugins.Recommendation: Search on WordPress admin screen and install it.
This plugin is hosted on Github.
Please feel free to make issue or send pull requests.
console.log only if SCRIPT_DEBUG is true.Object.assign in favor of lte IE11.vendor directory was missing.wpApiSettings of wp-api.wp-json/cookie/v1/nonce is pseudo and it’s not REST API actually, so you can refresh nonce with this endpoint. Normally, this refresh will be executed automatically, but if you get “rest_cookie_invalid_nonce”, try updating permalink from “Setting > Permalink”. Just click “Save” and that’s it.$secure flag is now false.| Version | Download | Type |
|---|---|---|
| 1.0.11 | Download | Stable |
| 1.0.10 | Download | Stable |
| 1.0.9 | Download | Stable |
| 1.0.8 | Download | Stable |
| 1.0.7 | Download | Stable |
| 1.0.6 | Download | Stable |
| 1.0.5 | Download | Stable |
| 1.0.4 | Download | Stable |
| 1.0.3 | Download | Stable |
| 1.0.2 | Download | Stable |
| 1.0.1 | Download | Stable |
| 1.0.0 | Download | Stable |
| Development | Download | Trunk |