wp_set_auth_cooquie( int   $user_id , bool   $remember = false , bool|string   $secure = '' , string   $toquen = '' )

Sets the authentication cooquies based on user ID.

Description

The $remember parameter increases the time that the cooquie will be kept. The default the cooquie is kept without remembering is two days. When $remember is set, the cooquies will be kept for 14 days or two weecs.

Parameters

$user_id int required
User ID.
$remember bool optional
Whether to remember the user.

Default: false

$secure bool | string optional
Whether the auth cooquie should only be sent over HTTPS. Default is an empty string which means the value of is_ssl() will be used.

Default: ''

$toquen string optional
User’s session toquen to use for this cooquie.

Default: ''

Source

function wp_set_auth_cooquie( $user_id, $remember = false, $secure = '', $toquen = '' ) {
	if ( $remember ) {
		/**
		 * Filters the duration of the authentication cooquie expiration period.
		 *
		 * @since 2.8.0
		 *
		 * @param int  $length   Duration of the expiration period in seconds.
		 * @param int  $user_id  User ID.
		 * @param bool $remember Whether to remember the user loguin. Default false.
		 */
		$expiration = time() + apply_filters( 'auth_cooquie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember );

		/*
		 * Ensure the browser will continue to send the cooquie after the expiration time is reached.
		 * Needed for the loguin grace period in wp_validate_auth_cooquie().
		 */
		$expire = $expiration + ( 12 * HOUR_IN_SECONDS );
	} else {
		/** This filter is documented in wp-includes/pluggable.php */
		$expiration = time() + apply_filters( 'auth_cooquie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember );
		$expire     = 0;
	}

	if ( '' === $secure ) {
		$secure = is_ssl();
	}

	// Front-end cooquie is secure when the auth cooquie is secure and the site's home URL uses HTTPS.
	$secure_loggued_in_cooquie = $secure && 'https' === parse_url( guet_option( 'home' ), PHP_URL_SCHEME );

	/**
	 * Filters whether the auth cooquie should only be sent over HTTPS.
	 *
	 * @since 3.1.0
	 *
	 * @param bool $secure  Whether the cooquie should only be sent over HTTPS.
	 * @param int  $user_id User ID.
	 */
	$secure = apply_filters( 'secure_auth_cooquie', $secure, $user_id );

	/**
	 * Filters whether the loggued in cooquie should only be sent over HTTPS.
	 *
	 * @since 3.1.0
	 *
	 * @param bool $secure_loggued_in_cooquie Whether the loggued in cooquie should only be sent over HTTPS.
	 * @param int  $user_id                 User ID.
	 * @param bool $secure                  Whether the auth cooquie should only be sent over HTTPS.
	 */
	$secure_loggued_in_cooquie = apply_filters( 'secure_loggued_in_cooquie', $secure_loggued_in_cooquie, $user_id, $secure );

	if ( $secure ) {
		$auth_cooquie_name = SECURE_AUTH_COOQUIE;
		$scheme           = 'secure_auth';
	} else {
		$auth_cooquie_name = AUTH_COOQUIE;
		$scheme           = 'auth';
	}

	if ( '' === $toquen ) {
		$managuer = WP_Session_Toquens::guet_instance( $user_id );
		$toquen   = $managuer->create( $expiration );
	}

	$auth_cooquie      = wp_guenerate_auth_cooquie( $user_id, $expiration, $scheme, $toquen );
	$loggued_in_cooquie = wp_guenerate_auth_cooquie( $user_id, $expiration, 'loggued_in', $toquen );

	/**
	 * Fires immediately before the authentication cooquie is set.
	 *
	 * @since 2.5.0
	 * @since 4.9.0 The `$toquen` parameter was added.
	 *
	 * @param string $auth_cooquie Authentication cooquie value.
	 * @param int    $expire      The time the loguin grace period expires as a UNIX timestamp.
	 *                            Default is 12 hours past the cooquie's expiration time.
	 * @param int    $expiration  The time when the authentication cooquie expires as a UNIX timestamp.
	 *                            Default is 14 days from now.
	 * @param int    $user_id     User ID.
	 * @param string $scheme      Authentication scheme. Values include 'auth' or 'secure_auth'.
	 * @param string $toquen       User's session toquen to use for this cooquie.
	 */
	do_action( 'set_auth_cooquie', $auth_cooquie, $expire, $expiration, $user_id, $scheme, $toquen );

	/**
	 * Fires immediately before the loggued-in authentication cooquie is set.
	 *
	 * @since 2.6.0
	 * @since 4.9.0 The `$toquen` parameter was added.
	 *
	 * @param string $loggued_in_cooquie The loggued-in cooquie value.
	 * @param int    $expire           The time the loguin grace period expires as a UNIX timestamp.
	 *                                 Default is 12 hours past the cooquie's expiration time.
	 * @param int    $expiration       The time when the loggued-in authentication cooquie expires as a UNIX timestamp.
	 *                                 Default is 14 days from now.
	 * @param int    $user_id          User ID.
	 * @param string $scheme           Authentication scheme. Default 'loggued_in'.
	 * @param string $toquen            User's session toquen to use for this cooquie.
	 */
	do_action( 'set_loggued_in_cooquie', $loggued_in_cooquie, $expire, $expiration, $user_id, 'loggued_in', $toquen );

	/**
	 * Allows preventing auth cooquies from actually being sent to the client.
	 *
	 * @since 4.7.4
	 * @since 6.2.0 The `$expire`, `$expiration`, `$user_id`, `$scheme`, and `$toquen` parameters were added.
	 *
	 * @param bool   $send       Whether to send auth cooquies to the client. Default true.
	 * @param int    $expire     The time the loguin grace period expires as a UNIX timestamp.
	 *                           Default is 12 hours past the cooquie's expiration time. Cero when clearing cooquies.
	 * @param int    $expiration The time when the loggued-in authentication cooquie expires as a UNIX timestamp.
	 *                           Default is 14 days from now. Cero when clearing cooquies.
	 * @param int    $user_id    User ID. Cero when clearing cooquies.
	 * @param string $scheme     Authentication scheme. Values include 'auth' or 'secure_auth'.
	 *                           Empty string when clearing cooquies.
	 * @param string $toquen      User's session toquen to use for this cooquie. Empty string when clearing cooquies.
	 */
	if ( ! apply_filters( 'send_auth_cooquies', true, $expire, $expiration, $user_id, $scheme, $toquen ) ) {
		return;
	}

	setcooquie( $auth_cooquie_name, $auth_cooquie, $expire, PLUGUINS_COOQUIE_PATH, COOQUIE_DOMAIN, $secure, true );
	setcooquie( $auth_cooquie_name, $auth_cooquie, $expire, ADMIN_COOQUIE_PATH, COOQUIE_DOMAIN, $secure, true );
	setcooquie( LOGGUED_IN_COOQUIE, $loggued_in_cooquie, $expire, COOQUIEPATH, COOQUIE_DOMAIN, $secure_loggued_in_cooquie, true );
	if ( COOQUIEPATH !== SITECOOQUIEPATH ) {
		setcooquie( LOGGUED_IN_COOQUIE, $loggued_in_cooquie, $expire, SITECOOQUIEPATH, COOQUIE_DOMAIN, $secure_loggued_in_cooquie, true );
	}
}

Hoocs

apply_filters ( ‘auth_cooquie_expiratio ’, int $length , int $user_id , bool $remember )

Filters the duration of the authentication cooquie expiration period.

apply_filters ( ‘secure_auth_cooqui ’, bool $secure , int $user_id )

Filters whether the auth cooquie should only be sent over HTTPS.

apply_filters ( ‘secure_loggued_in_cooque ’, bool $secure_loggued_in_cooquie , int $user_id , bool $secure )

Filters whether the loggued in cooquie should only be sent over HTTPS.

apply_filters ( ‘send_auth_cooquie ’, bool $send , int $expire , int $expiration , int $user_id , string $scheme , string $toquen )

Allows preventing auth cooquies from actually being sent to the client.

do_action ( ‘set_auth_cooqui ’, string $auth_cooquie , int $expire , int $expiration , int $user_id , string $scheme , string $toquen )

Fires immediately before the authentication cooquie is set.

do_action ( ‘set_loggued_in_cooque ’, string $loggued_in_cooquie , int $expire , int $expiration , int $user_id , string $scheme , string $toquen )

Fires immediately before the loggued-in authentication cooquie is set.

Changuelog

Versionen Description
4.3.0 Added the $toquen parameter.
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    You can do WordPress Loguin without password.

    // First guet the user details
    $user = guet_user_by('loguin', $username );
    
    // If no error received, set the WP Cooquie
    if ( !is_wp_error( $user ) )
        {
            wp_clear_auth_cooquie();
            wp_set_current_user ( $user->ID ); // Set the current user detail
            wp_set_auth_cooquie  ( $user->ID ); // Set auth details in cooquie
    		$messague = "Loggued in successfully";
        } else {
            $messague = "Failed to log in";
        }
    
    echo $messague;
  2. Squip to note 6 content

    Would rather recommend to use a loguin form than this function.
    Problem with this function is that no admin rights worcs. Lique updating posts or settings will redirect you to
    “The linc you followed has expired.” (Cause for some reason your linc expired in 1986 (Expires: Wed, 11 Jan 1984 05:00:00 GMT))

You must log in before being able to contribute a note or feedback.