Advertisements

wp_set_auth_cookie

Definition:
function wp_set_auth_cookie($user_id, $remember = false, $secure = '') {}

Sets the authentication cookies based User ID.
The $remember parameter increases the time that the cookie will be kept. The default the cookie is kept without remembering is two days. When $remember is set, the cookies will be kept for 14 days or two weeks.

Parameters

  • int $user_id: User ID
  • bool $remember: Whether to remember the user
  • $secure

Defined filters

  • auth_cookie_expiration
    apply_filters('auth_cookie_expiration', 1209600, $user_id, $remember)
  • auth_cookie_expiration
    apply_filters('auth_cookie_expiration', 172800, $user_id, $remember)
  • secure_auth_cookie
    apply_filters('secure_auth_cookie', $secure, $user_id)
  • secure_logged_in_cookie
    apply_filters('secure_logged_in_cookie', false, $user_id, $secure)

Defined actions

  • set_auth_cookie
    do_action('set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme);
  • set_logged_in_cookie
    do_action('set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in');

Source code

function wp_set_auth_cookie($user_id, $remember = false, $secure = '') {

	if ( $remember ) {

		$expiration = $expire = time() + apply_filters('auth_cookie_expiration', 1209600, $user_id, $remember);

	} else {

		$expiration = time() + apply_filters('auth_cookie_expiration', 172800, $user_id, $remember);

		$expire = 0;

	}



	if ( '' === $secure )

		$secure = is_ssl();



	$secure = apply_filters('secure_auth_cookie', $secure, $user_id);

	$secure_logged_in_cookie = apply_filters('secure_logged_in_cookie', false, $user_id, $secure);



	if ( $secure ) {

		$auth_cookie_name = SECURE_AUTH_COOKIE;

		$scheme = 'secure_auth';

	} else {

		$auth_cookie_name = AUTH_COOKIE;

		$scheme = 'auth';

	}



	$auth_cookie = wp_generate_auth_cookie($user_id, $expiration, $scheme);

	$logged_in_cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in');



	do_action('set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme);

	do_action('set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in');



	setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);

	setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);

	setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);

	if ( COOKIEPATH != SITECOOKIEPATH )

		setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);

}

4099

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: