bp_member_switching_clear_olduser_cookie( bool $clear_all = true )

Clears the cookies containing the originating user, or pops the latest item off the end if there’s more than one.

Description

Parameters

$clear_all

(Optional) Whether to clear the cookies (as opposed to just popping the last user off the end).

Default value: true

Source

File: bp-members/bp-members-functions.php

function bp_member_switching_clear_olduser_cookie( $clear_all = true ) {
	$auth_cookie = bp_member_switching_get_auth_cookie();
	if ( ! empty( $auth_cookie ) ) {
		array_pop( $auth_cookie );
	}
	if ( $clear_all || empty( $auth_cookie ) ) {

		/** This filter is documented in wp-includes/pluggable.php */
		if ( ! apply_filters( 'send_auth_cookies', true ) ) {
			return;
		}

		$expire = time() - 31536000;
		setcookie( BP_MEMBER_SWITCHING_COOKIE, ' ', $expire, SITECOOKIEPATH, COOKIE_DOMAIN );
		setcookie( BP_MEMBER_SWITCHING_SECURE_COOKIE, ' ', $expire, SITECOOKIEPATH, COOKIE_DOMAIN );
		setcookie( BP_MEMBER_SWITCHING_OLDUSER_COOKIE, ' ', $expire, COOKIEPATH, COOKIE_DOMAIN );
	} else {
		if ( BP_Core_Members_Switching::secure_auth_cookie() ) {
			$scheme = 'secure_auth';
		} else {
			$scheme = 'auth';
		}

		$old_cookie = end( $auth_cookie );

		$old_user_id = wp_validate_auth_cookie( $old_cookie, $scheme );
		if ( $old_user_id ) {
			$parts = wp_parse_auth_cookie( $old_cookie, $scheme );
			bp_member_switching_set_olduser_cookie( $old_user_id, true, $parts['token'] );
		}
	}
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.