Are transients private or public?

Transients are just database keys that expire. It’s like telling WordPress you want it to remember a certain piece of information, but for a limited time. In general, transients are accessible to PHP through any request. But since they’re server-side, transients are only exposed to front-end users if you as the developer expose them. A … Read more

Ban a user and end their session

Use wp_logout(). It calls wp_clear_auth_cookie() and invalidates the current log-in information immediately. Sample code, not tested: add_action( ‘init’, ‘log_out_banned_user’ ); function log_out_banned_user() { if ( ! is_user_logged_in() ) return; $user = wp_get_current_user(); if ( ! get_user_option( ‘rc_banned’, $user->ID, false ) ) return; wp_logout(); wp_redirect( home_url( “https://wordpress.stackexchange.com/” ) ); exit; }

Destroy user sessions based on user ID

OK, simple solution after digging in the WordPress code. // get all sessions for user with ID $user_id $sessions = WP_Session_Tokens::get_instance($user_id); // we have got the sessions, destroy them all! $sessions->destroy_all(); This will log the user with ID $user_id out of WordPress. Use case: My use case for this is when a user is approved … Read more

Extend WordPress (4.x) session and nonce

Your problem is that you call wp_logout_url immediately after wp_set_auth_cookie. wp_set_auth_cookie() does some setcookie() calls. Unfortunately setcookie doesn’t make the new value available instantly in the PHP global $_COOKIE. It must be set through a new HTTP Request first. wp_logout_url() (via wp_nonce_url > wp_create_nonce > wp_get_session_token > wp_parse_auth_cookie) fetches $_COOKIE[LOGGED_IN_COOKIE] in order to create a … Read more

How to share cookies and sessions between domain and subdomain?

I’ll skip steps related to sharing DB and sharing users data and meta, based on assumption that you’ve done it correctly. Let’s concentrate on wp-config.php of both sites. These are defines that MUST BE IDENTICAL for both sites: define(‘COOKIE_DOMAIN’, ‘.domain.com’); // your main domain define(‘COOKIEPATH’, “https://wordpress.stackexchange.com/”); define(‘COOKIEHASH’, md5(‘domain.com’)); // notice absence of a ‘.’ in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)