✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ server366.web-hosting.com ​🇻​♯➤ 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2025

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 67.223.118.204 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.243
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /home/builxejc/public_html/wp-content/plugins/woocommerce/includes//class-wc-session-handler.php
<?php
/**
 * Handle data for the current customers session.
 * Implements the WC_Session abstract class.
 *
 * From 2.5 this uses a custom table for session storage. Based on https://github.com/kloon/woocommerce-large-sessions.
 *
 * @class    WC_Session_Handler
 * @package  WooCommerce\Classes
 */

declare(strict_types=1);

use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Utilities\StringUtil;
use Automattic\WooCommerce\StoreApi\Utilities\CartTokenUtils;

defined( 'ABSPATH' ) || exit;

/**
 * Session handler class.
 */
class WC_Session_Handler extends WC_Session {

	/**
	 * Cookie name used for the session.
	 *
	 * @var string cookie name
	 */
	protected $_cookie = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

	/**
	 * Stores session expiry.
	 *
	 * @var int session due to expire timestamp
	 */
	protected $_session_expiring = 0; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

	/**
	 * Stores session due to expire timestamp.
	 *
	 * @var int session expiration timestamp
	 */
	protected $_session_expiration = 0; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

	/**
	 * True when the cookie exists.
	 *
	 * @var bool Based on whether a cookie exists.
	 */
	protected $_has_cookie = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

	/**
	 * Table name for session data.
	 *
	 * @var string Custom session table name
	 */
	protected $_table = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

	/**
	 * Constructor for the session class.
	 */
	public function __construct() {
		/**
		 * Filter the cookie name.
		 *
		 * @since 3.6.0
		 *
		 * @param string $cookie Cookie name.
		 */
		$this->_cookie = (string) apply_filters( 'woocommerce_cookie', 'wp_woocommerce_session_' . COOKIEHASH );
		$this->_table  = $GLOBALS['wpdb']->prefix . 'woocommerce_sessions';
		$this->set_session_expiration();
	}

	/**
	 * Init hooks and session data.
	 *
	 * @since 3.3.0
	 */
	public function init() {
		$this->init_hooks();
		$this->init_session();
	}

	/**
	 * Initialize the hooks.
	 */
	protected function init_hooks() {
		add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 );
		add_action( 'wp', array( $this, 'maybe_set_customer_session_cookie' ), 99 );
		add_action( 'template_redirect', array( $this, 'destroy_session_if_empty' ), 999 );
		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
		add_action( 'wp_logout', array( $this, 'destroy_session' ) );

		if ( ! is_user_logged_in() ) {
			add_filter( 'nonce_user_logged_out', array( $this, 'maybe_update_nonce_user_logged_out' ), 10, 2 );
		}
	}

	/**
	 * Initialize the session from either the request or the cookie.
	 */
	private function init_session() {
		if ( ! $this->init_session_from_request() ) {
			$this->init_session_cookie();
		}
	}

	/**
	 * Initialize the session from the query string parameter.
	 *
	 * If the current user is logged in, the token session will replace the current user's session.
	 * If the current user is logged out, the token session will be cloned to a new session.
	 *
	 * Only guest sessions are restored, hence the check for the t_ prefix on the customer ID.
	 *
	 * @return bool
	 */
	private function init_session_from_request() {
		$session_token = is_string( $_GET['session'] ?? '' ) ? wc_clean( wp_unslash( $_GET['session'] ?? '' ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended

		if ( empty( $session_token ) || ! CartTokenUtils::validate_cart_token( $session_token ) ) {
			return false;
		}

		$payload = CartTokenUtils::get_cart_token_payload( $session_token );

		if ( ! $this->is_customer_guest( $payload['user_id'] ) || ! $this->session_exists( $payload['user_id'] ) ) {
			return false;
		}

		// Check to see if the current user has a session before proceeding with token handling.
		$cookie = $this->get_session_cookie();

		if ( $cookie ) {
			// User owns this token. Return and use cookie session.
			if ( $cookie[0] === $payload['user_id'] ) {
				return false;
			}

			$cookie_session_data = (array) $this->get_session( $cookie[0], array() );

			// Cookie session was originally created via this token. Return and use cookie session to prevent creating a new clone.
			if ( isset( $cookie_session_data['previous_customer_id'] ) && $cookie_session_data['previous_customer_id'] === $payload['user_id'] ) {
				return false;
			}
		}

		// Generate new customer ID for the new session before cloning the data.
		$this->_customer_id = $this->generate_customer_id();
		$this->set_customer_session_cookie( true );
		$this->clone_session_data( $payload['user_id'] );

		return true;
	}

	/**
	 * Setup cookie and customer ID.
	 *
	 * @since 3.6.0
	 */
	public function init_session_cookie() {
		$cookie = $this->get_session_cookie();

		if ( ! $cookie ) {
			// If there is no cookie, generate a new session/customer ID.
			$this->_customer_id = $this->generate_customer_id();
			$this->_data        = $this->get_session_data();
			return;
		}

		// Customer ID will be an MD5 hash id this is a guest session.
		$this->_customer_id        = $cookie[0];
		$this->_session_expiration = (int) $cookie[1];
		$this->_session_expiring   = (int) $cookie[2];
		$this->_has_cookie         = true;

		$this->restore_session_data();

		/**
		 * This clears the session if the cookie is invalid.
		 */
		if ( ! $this->is_session_cookie_valid() ) {
			$this->destroy_session();
		}

		// If the user logs in, update session.
		if ( is_user_logged_in() && (string) get_current_user_id() !== $this->get_customer_id() ) {
			$this->migrate_guest_session_to_user_session();
		}

		// Update session if its close to expiring.
		if ( $this->is_session_expiring() ) {
			$this->set_session_expiration();
			$this->update_session_timestamp( $this->get_customer_id(), $this->_session_expiration );
		}
	}

	/**
	 * Clones a session to the current session. Exclude customer details for privacy reasons.
	 *
	 * @param string $clone_from_customer_id The customer ID to clone from.
	 */
	private function clone_session_data( string $clone_from_customer_id ) {
		$session_data                         = (array) $this->get_session( $clone_from_customer_id, array() );
		$session_data['previous_customer_id'] = $clone_from_customer_id;
		$session_data                         = array_diff_key( $session_data, array( 'customer' => true ) );
		$this->_data                          = $session_data;
		$this->_dirty                         = true;
		$this->save_data();
	}

	/**
	 * Migrates a guest session to the current user session.
	 */
	private function migrate_guest_session_to_user_session() {
		$guest_session_id = $this->_customer_id;
		$user_session_id  = (string) get_current_user_id();

		$this->_data        = $this->get_session( $guest_session_id, array() );
		$this->_dirty       = true;
		$this->_customer_id = $user_session_id;
		$this->save_data( $guest_session_id );

		/**
		 * Fires after a customer has logged in, and their guest session id has been
		 * deleted with its data migrated to a customer id.
		 *
		 * This hook gives extensions the chance to connect the old session id to the
		 * customer id, if the key is being used externally.
		 *
		 * @since 8.8.0
		 *
		 * @param string $guest_session_id The former session ID, as generated by `::generate_customer_id()`.
		 * @param string $user_session_id The Customer ID that the former session was converted to.
		 */
		do_action( 'woocommerce_guest_session_to_user_id', $guest_session_id, $user_session_id );

		$this->set_session_expiration();
		$this->update_session_timestamp( $this->get_customer_id(), $this->_session_expiration );
		// Set cookie to user session. Otherwise next request still has guest id and the session is empty.
		$this->set_customer_session_cookie( true );
	}

	/**
	 * Restore the session data from the database.
	 *
	 * @since 10.0.0
	 */
	private function restore_session_data() {
		$session_data = $this->get_session_data();

		/**
		 * Filters the session data when restoring from storage during initialization.
		 *
		 * This filter allows you to:
		 * 1. Modify the session data before it's loaded, including adding or removing specific session data entries
		 * 2. Clear the entire session by returning an empty array
		 *
		 * Note: If the filtered data is empty, the session will be destroyed and the
		 * guest's session cookie will be removed. This can be useful for high-traffic
		 * sites that prioritize page caching over maintaining all session data.
		 *
		 * @since 9.9.0
		 *
		 * @param array $session_data The session data loaded from storage.
		 * @return array Modified session data to be used for initialization.
		 */
		$this->_data = (array) apply_filters( 'woocommerce_restored_session_data', $session_data );
	}

	/**
	 * Checks if session cookie is expired, or belongs to a logged out user.
	 *
	 * @return bool Whether session cookie is valid.
	 */
	private function is_session_cookie_valid() {
		// If session is expired, session cookie is invalid.
		if ( time() > $this->_session_expiration ) {
			return false;
		}

		// If user has logged out, session cookie is invalid.
		if ( ! is_user_logged_in() && ! $this->is_customer_guest( $this->get_customer_id() ) ) {
			return false;
		}

		// Session from a different user is not valid. (Although from a guest user will be valid).
		if ( is_user_logged_in() && ! $this->is_customer_guest( $this->get_customer_id() ) && (string) get_current_user_id() !== $this->get_customer_id() ) {
			return false;
		}

		return true;
	}

	/**
	 * Hooks into the wp action to maybe set the session cookie if the user is on a certain page e.g. a checkout endpoint.
	 *
	 * Certain gateways may rely on sessions and this ensures a session is present even if the customer does not have a
	 * cart.
	 */
	public function maybe_set_customer_session_cookie() {
		if ( is_wc_endpoint_url( 'order-pay' ) ) {
			$this->set_customer_session_cookie( true );
		}
	}

	/**
	 * Hash a value using wp_fast_hash (from WP 6.8 onwards).
	 *
	 * This method can be removed when the minimum version supported is 6.8.
	 *
	 * @param string $message Value to hash.
	 * @return string Hashed value.
	 */
	private function hash( string $message ) {
		if ( function_exists( 'wp_fast_hash' ) ) {
			return wp_fast_hash( $message );
		}
		return hash_hmac( 'md5', $message, wp_hash( $message ) );
	}

	/**
	 * Verify a hash using wp_verify_fast_hash (from WP 6.8 onwards).
	 *
	 * This method can be removed when the minimum version supported is 6.8.
	 *
	 * @param string $message Message to verify.
	 * @param string $hash Hash to verify.
	 * @return bool Whether the hash is valid.
	 */
	private function verify_hash( string $message, string $hash ) {
		if ( function_exists( 'wp_verify_fast_hash' ) ) {
			return wp_verify_fast_hash( $message, $hash );
		}
		return hash_equals( hash_hmac( 'md5', $message, wp_hash( $message ) ), $hash );
	}

	/**
	 * Sets the session cookie on-demand (usually after adding an item to the cart).
	 *
	 * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
	 *
	 * Warning: Cookies will only be set if this is called before the headers are sent.
	 *
	 * @param bool $set Should the session cookie be set.
	 */
	public function set_customer_session_cookie( $set ) {
		if ( $set ) {
			$cookie_hash  = $this->hash( $this->get_customer_id() . '|' . (string) $this->_session_expiration );
			$cookie_value = $this->get_customer_id() . '|' . (string) $this->_session_expiration . '|' . (string) $this->_session_expiring . '|' . $cookie_hash;

			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
				wc_setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
			}

			$this->_has_cookie = true;
		}
	}

	/**
	 * Should the session cookie be secure?
	 *
	 * @since 3.6.0
	 * @return bool
	 */
	protected function use_secure_cookie() {
		/**
		 * Filter whether to use a secure cookie.
		 *
		 * @since 3.6.0
		 *
		 * @param bool $use_secure_cookie Whether to use a secure cookie.
		 */
		return (bool) apply_filters( 'wc_session_use_secure_cookie', wc_site_is_https() && is_ssl() );
	}

	/**
	 * Return true if the current user has an active session, i.e. a cookie to retrieve values.
	 *
	 * @return bool
	 */
	public function has_session() {
		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in();
	}

	/**
	 * Checks if the session is expiring.
	 *
	 * @return bool Whether session is expiring.
	 */
	private function is_session_expiring() {
		return time() > $this->_session_expiring;
	}

	/**
	 * Set session expiration.
	 */
	public function set_session_expiration() {
		$default_expiring_seconds   = DAY_IN_SECONDS;
		$default_expiration_seconds = is_user_logged_in() ? WEEK_IN_SECONDS : 2 * DAY_IN_SECONDS;
		$max_expiration_seconds     = MONTH_IN_SECONDS;
		$max_expiring_seconds       = $max_expiration_seconds - DAY_IN_SECONDS;
		$session_limit_exceeded     = false;

		/**
		 * Filters the session expiration.
		 *
		 * @since 5.0.0
		 * @param int $expiration_seconds The expiration time in seconds.
		 */
		$expiring_seconds = intval( apply_filters( 'wc_session_expiring', $default_expiring_seconds ) ) ?: $default_expiring_seconds; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found

		if ( $expiring_seconds > $max_expiring_seconds ) {
			$session_limit_exceeded = true;
		}
		/**
		 * Filters the session expiration.
		 *
		 * @since 5.0.0
		 * @param int $expiration_seconds The expiration time in seconds.
		 */
		$expiration_seconds = intval( apply_filters( 'wc_session_expiration', $default_expiration_seconds ) ) ?: $default_expiration_seconds; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found

		// We limit the expiration time to 30 days to avoid performance issues and the session table growing too large.
		if ( $expiration_seconds > $max_expiration_seconds ) {
			$session_limit_exceeded = true;
		}

		if ( $session_limit_exceeded ) {
			$transient_key = 'wc_session_handler_warning';
			if ( false === get_transient( $transient_key ) ) {
				wc_get_logger()->warning(
					sprintf(
						'Keeping sessions for longer than %d days can cause performance issues and larger session tables. Monitor usage and adjust lifetimes via the wc_session_expiring and wc_session_expiration filters as needed.',
						$max_expiration_seconds / DAY_IN_SECONDS
					),
					array( 'source' => 'wc_session_handler' )
				);
				set_transient( $transient_key, true, $max_expiration_seconds );
			}
		}

		// If the expiring time is greater than the expiration time, set the expiring time to 90% of the expiration time.
		if ( $expiring_seconds > $expiration_seconds ) {
			$expiring_seconds = $expiration_seconds * 0.9;
		}

		$this->_session_expiring   = time() + $expiring_seconds;
		$this->_session_expiration = time() + $expiration_seconds;
	}

	/**
	 * Generate a unique customer ID for guests, or return user ID if logged in.
	 *
	 * @return string
	 */
	public function generate_customer_id() {
		return is_user_logged_in() ? (string) get_current_user_id() : wc_rand_hash( 't_', 30 );
	}

	/**
	 * Checks if this is an auto-generated customer ID.
	 *
	 * @param string $customer_id Customer ID to check.
	 * @return bool Whether customer ID is randomly generated.
	 */
	private function is_customer_guest( $customer_id ) {
		return empty( $customer_id ) || 't_' === substr( $customer_id, 0, 2 );
	}

	/**
	 * Get session unique ID for requests if session is initialized or user ID if logged in.
	 * Introduced to help with unit tests.
	 *
	 * @since 5.3.0
	 * @return string
	 */
	public function get_customer_unique_id() {
		$customer_id = '';

		if ( $this->has_session() && $this->get_customer_id() ) {
			$customer_id = $this->get_customer_id();
		} elseif ( is_user_logged_in() ) {
			$customer_id = (string) get_current_user_id();
		}

		return $customer_id;
	}

	/**
	 * Get the session cookie, if set. Otherwise return false.
	 *
	 * Session cookies without a customer ID are invalid.
	 *
	 * @return bool|array
	 */
	public function get_session_cookie() {
		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wc_clean( wp_unslash( (string) $_COOKIE[ $this->_cookie ] ) ) : '';

		if ( empty( $cookie_value ) ) {
			return false;
		}

		// Check if the cookie value contains '||' instead of '|' to support older versions of the cookie. This can be removed in WC 11.0.0.
		if ( strpos( $cookie_value, '||' ) !== false ) {
			$parsed_cookie = explode( '||', $cookie_value );
		} else {
			$parsed_cookie = explode( '|', $cookie_value );
		}

		if ( count( $parsed_cookie ) !== 4 ) {
			return false;
		}

		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = $parsed_cookie;

		if ( empty( $customer_id ) ) {
			return false;
		}

		$verify_hash = $this->verify_hash( $customer_id . '|' . $session_expiration, $cookie_hash );

		if ( ! $verify_hash ) {
			return false;
		}

		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
	}

	/**
	 * Get session data fresh from storage.
	 *
	 * This re-reads session data from the database rather than returning
	 * in-memory data, ensuring the latest persisted state is returned.
	 *
	 * @return array
	 */
	public function get_session_data() {
		return $this->has_session() ? (array) $this->get_session( $this->get_customer_id(), array() ) : array();
	}

	/**
	 * Gets a cache prefix. This is used in session names so the entire cache can be invalidated with 1 function call.
	 *
	 * @return string
	 */
	private function get_cache_prefix() {
		return WC_Cache_Helper::get_cache_prefix( WC_SESSION_CACHE_GROUP );
	}

	/**
	 * Save data and delete guest session.
	 *
	 * @param string|mixed $old_session_key Optional session ID prior to user log-in.  If $old_session_key is not tied
	 *                                      to a user, the session will be deleted with the assumption that it was migrated
	 *                                      to the current session being saved.
	 */
	public function save_data( $old_session_key = '' ) {
		// Dirty if something changed - prevents saving nothing new.
		if ( $this->_dirty && $this->has_session() ) {
			global $wpdb;

			$wpdb->query(
				$wpdb->prepare(
					'INSERT INTO %i (`session_key`, `session_value`, `session_expiry`) VALUES (%s, %s, %d)
 					ON DUPLICATE KEY UPDATE `session_value` = VALUES(`session_value`), `session_expiry` = VALUES(`session_expiry`)',
					$this->_table,
					$this->get_customer_id(),
					maybe_serialize( $this->_data ),
					$this->_session_expiration
				)
			);
			wp_cache_set( $this->get_cache_prefix() . $this->get_customer_id(), $this->_data, WC_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
			$this->_dirty = false;

			/**
			 * Ideally, the removal of guest session data migrated to a logged-in user would occur within
			 * self::init_session_cookie() upon user login detection initially occurs. However, since some third-party
			 * extensions override this method, relocating this logic could break backward compatibility.
			 */
			if ( ! empty( $old_session_key ) && $this->get_customer_id() !== $old_session_key && ! is_object( get_user_by( 'id', $old_session_key ) ) ) {
				$this->delete_session( $old_session_key );
			}
		}
	}

	/**
	 * Destroy all session data.
	 */
	public function destroy_session() {
		$this->delete_session( $this->get_customer_id() );
		$this->forget_session();
		$this->set_session_expiration();
	}

	/**
	 * Forget all session data without destroying it.
	 */
	public function forget_session() {
		wc_setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );

		if ( ! is_admin() ) {
			include_once WC_ABSPATH . 'includes/wc-cart-functions.php';
			wc_empty_cart();
		}

		$this->_data        = array();
		$this->_dirty       = false;
		$this->_customer_id = $this->generate_customer_id();
		$this->_has_cookie  = false;
	}

	/**
	 * When a user is logged out, ensure they have a unique nonce to manage cart and more using the customer/session ID.
	 * This filter runs everything `wp_verify_nonce()` and `wp_create_nonce()` gets called.
	 *
	 * @since 5.3.0
	 * @param int        $uid    User ID.
	 * @param int|string $action The nonce action.
	 * @return int|string
	 */
	public function maybe_update_nonce_user_logged_out( $uid, $action ) {
		if ( is_string( $action ) && StringUtil::starts_with( $action, 'woocommerce' ) ) {
			return $this->has_session() && $this->get_customer_id() ? $this->get_customer_id() : $uid;
		}
		return $uid;
	}

	/**
	 * Cleanup session data from the database and clear caches.
	 */
	public function cleanup_sessions() {
		global $wpdb;

		// Batch size of 100 and sleep time of 10ms = max 100 SQL queries and 10K entries deletion per second.
		$batch_size            = 100;
		$deleted_entries_total = 0;
		do {
			$deleted_entries_count  = (int) $wpdb->query(
				$wpdb->prepare(
					'DELETE FROM %i WHERE session_expiry < %d ORDER BY session_expiry LIMIT %d',
					$this->_table,
					time(),
					$batch_size
				)
			);
			$deleted_entries_total += $deleted_entries_count;
			usleep( ( 10_000 / $batch_size ) * $deleted_entries_count );
		} while ( $deleted_entries_count === $batch_size );

		if ( $deleted_entries_total > 0 && class_exists( 'WC_Cache_Helper' ) ) {
			WC_Cache_Helper::invalidate_cache_group( WC_SESSION_CACHE_GROUP );
		}
	}

	/**
	 * Returns the session.
	 *
	 * @param string $customer_id Customer ID.
	 * @param mixed  $default_value Default session value.
	 * @return mixed Returns either the session data or the default value. Returns false if WP setup is in progress.
	 */
	public function get_session( $customer_id, $default_value = false ) {
		global $wpdb;

		if ( Constants::is_defined( 'WP_SETUP_CONFIG' ) ) {
			return $default_value;
		}

		// Try to get it from the cache, it will return false if not present or if object cache not in use.
		$value = wp_cache_get( $this->get_cache_prefix() . $customer_id, WC_SESSION_CACHE_GROUP );

		if ( false === $value ) {
			$value = $wpdb->get_var( $wpdb->prepare( 'SELECT session_value FROM %i WHERE session_key = %s', $this->_table, $customer_id ) );

			if ( is_null( $value ) ) {
				$value = $default_value;
			}

			$cache_duration = $this->_session_expiration - time();
			if ( 0 < $cache_duration ) {
				wp_cache_add( $this->get_cache_prefix() . $customer_id, $value, WC_SESSION_CACHE_GROUP, $cache_duration );
			}
		}

		return maybe_unserialize( $value );
	}

	/**
	 * Delete the session from the cache and database.
	 *
	 * @param string $customer_id Customer session ID.
	 */
	public function delete_session( $customer_id ) {
		if ( ! $customer_id ) {
			return;
		}
		$GLOBALS['wpdb']->delete( $this->_table, array( 'session_key' => $customer_id ) );
		wp_cache_delete( $this->get_cache_prefix() . $customer_id, WC_SESSION_CACHE_GROUP );
	}

	/**
	 * Update the session expiry timestamp.
	 *
	 * @param string $customer_id Customer ID.
	 * @param int    $timestamp Timestamp to expire the cookie.
	 */
	public function update_session_timestamp( $customer_id, $timestamp ) {
		if ( ! $customer_id ) {
			return;
		}
		$GLOBALS['wpdb']->update( $this->_table, array( 'session_expiry' => $timestamp ), array( 'session_key' => $customer_id ), array( '%d' ) );
	}

	/**
	 * Destroys the WooCommerce session if it contains no data for non-logged-in users.
	 *
	 * This method helps improve caching performance by removing session cookies when they
	 * are no longer needed, allowing non-logged-in customers to receive cached pages.
	 * Only runs if the destroy-empty-sessions feature is enabled.
	 *
	 * @return void
	 *
	 * @since 10.3.0
	 *
	 * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
	 */
	public function destroy_session_if_empty() {
		if ( is_user_logged_in() || ! $this->_has_cookie ) {
			return;
		}

		if ( ! isset( $_COOKIE[ $this->_cookie ] ) ) {
			// If $_COOKIE isn't set, then something triggered setting the cookie during this request. So we won't
			// yet destroy the session if it is empty to expand compatibility at the cost of one additional request being uncached.
			return;
		}

		if ( ! empty( $this->_data ) ) {
			return;
		}

		if ( is_object( WC()->cart ) && ! WC()->cart->is_empty() ) {
			// There is a pending cart to save that isn't yet in the session data.
			return;
		}

		$feature_controller = wc_get_container()->get( FeaturesController::class );
		if ( ! $feature_controller->feature_is_enabled( 'destroy-empty-sessions' ) ) {
			return;
		}

		$this->destroy_session();
	}

	/**
	 * Check if a session exists in the database.
	 *
	 * @param string $customer_id Customer ID.
	 * @return bool
	 */
	private function session_exists( $customer_id ) {
		return $customer_id && null !== $GLOBALS['wpdb']->get_var( $GLOBALS['wpdb']->prepare( 'SELECT session_key FROM %i WHERE session_key = %s', $this->_table, $customer_id ) );
	}
}


Current_dir [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
abstracts
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
admin
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
blocks
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
cli
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
customizer
--
16 Jun 2026 10.17 AM
builxejc / builxejc
0755
data-stores
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
emails
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
export
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
gateways
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
import
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
integrations
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
interfaces
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
legacy
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
libraries
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
log-handlers
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
payment-tokens
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
product-usage
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
queue
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
react-admin
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
rest-api
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
shipping
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
shortcodes
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
theme-support
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
tracks
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
traits
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
walkers
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
wccom-site
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
widgets
--
9 Jun 2026 8.39 AM
builxejc / builxejc
0755
class-wc-ajax.php
131.473 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-auth.php
12.69 KB
30 Jul 2024 7.31 PM
builxejc / builxejc
0644
class-wc-autoloader.php
5.268 KB
6 Oct 2025 5.56 PM
builxejc / builxejc
0644
class-wc-background-emailer.php
4.677 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-background-updater.php
3.452 KB
20 Aug 2020 11.18 PM
builxejc / builxejc
0644
class-wc-brands-brand-settings-manager.php
1.783 KB
23 Sep 2024 8.44 PM
builxejc / builxejc
0644
class-wc-brands-coupons.php
6.894 KB
21 Jan 2025 6.53 PM
builxejc / builxejc
0644
class-wc-brands.php
34.8 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
class-wc-breadcrumb.php
10.41 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-cache-helper.php
12.792 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-cart-fees.php
3.367 KB
26 Sep 2023 9.42 PM
builxejc / builxejc
0644
class-wc-cart-session.php
25.366 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-cart-totals.php
28.479 KB
29 Jul 2025 12.34 PM
builxejc / builxejc
0644
class-wc-cart.php
75.572 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-checkout.php
50.352 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-cli.php
3.339 KB
1 Sep 2025 11.44 PM
builxejc / builxejc
0644
class-wc-comments.php
23.077 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-countries.php
51.687 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-coupon.php
44.637 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-customer-download-log.php
3.371 KB
20 Aug 2020 11.18 PM
builxejc / builxejc
0644
class-wc-customer-download.php
10.339 KB
30 Jul 2024 7.31 PM
builxejc / builxejc
0644
class-wc-customer.php
33.277 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-data-exception.php
1.29 KB
23 May 2018 7.30 PM
builxejc / builxejc
0644
class-wc-data-store.php
6.594 KB
19 Oct 2022 12.34 AM
builxejc / builxejc
0644
class-wc-datetime.php
2.256 KB
20 Apr 2022 6.50 AM
builxejc / builxejc
0644
class-wc-deprecated-action-hooks.php
6.588 KB
27 Feb 2024 6.59 PM
builxejc / builxejc
0644
class-wc-deprecated-filter-hooks.php
7.342 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-discounts.php
36.644 KB
29 Jul 2025 12.34 PM
builxejc / builxejc
0644
class-wc-download-handler.php
28.372 KB
18 Dec 2024 10.19 PM
builxejc / builxejc
0644
class-wc-emails.php
39.638 KB
25 May 2026 2.01 PM
builxejc / builxejc
0644
class-wc-embed.php
4.24 KB
21 Jan 2025 6.53 PM
builxejc / builxejc
0644
class-wc-form-handler.php
48.171 KB
9 Mar 2026 4.07 PM
builxejc / builxejc
0644
class-wc-frontend-scripts.php
34.438 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-geo-ip.php
30.429 KB
6 Oct 2025 5.56 PM
builxejc / builxejc
0644
class-wc-geolite-integration.php
1.988 KB
16 Jan 2020 6.10 AM
builxejc / builxejc
0644
class-wc-geolocation.php
11.464 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-https.php
4.335 KB
20 Jun 2023 11.45 PM
builxejc / builxejc
0644
class-wc-install.php
116.715 KB
25 May 2026 2.01 PM
builxejc / builxejc
0644
class-wc-integrations.php
1.277 KB
20 Aug 2020 11.18 PM
builxejc / builxejc
0644
class-wc-log-levels.php
3.898 KB
30 Jan 2024 11.24 PM
builxejc / builxejc
0644
class-wc-logger.php
9.413 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-meta-data.php
2.207 KB
20 Apr 2022 6.50 AM
builxejc / builxejc
0644
class-wc-order-factory.php
8.979 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-order-item-coupon.php
4.077 KB
22 Dec 2021 12.24 AM
builxejc / builxejc
0644
class-wc-order-item-fee.php
9.988 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
class-wc-order-item-meta.php
5.803 KB
22 Dec 2021 12.24 AM
builxejc / builxejc
0644
class-wc-order-item-product.php
17.606 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-order-item-shipping.php
9.585 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
class-wc-order-item-tax.php
6.488 KB
22 Dec 2021 12.24 AM
builxejc / builxejc
0644
class-wc-order-item.php
21.394 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
class-wc-order-query.php
2.552 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-order-refund.php
5.991 KB
12 May 2025 9.07 PM
builxejc / builxejc
0644
class-wc-order.php
78.376 KB
11 May 2026 5.17 PM
builxejc / builxejc
0644
class-wc-payment-gateways.php
14.373 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-payment-tokens.php
6.24 KB
23 Nov 2022 5.58 AM
builxejc / builxejc
0644
class-wc-post-data.php
39.094 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-post-types.php
33.158 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-privacy-background-process.php
1.79 KB
3 Mar 2025 10.28 PM
builxejc / builxejc
0644
class-wc-privacy-erasers.php
13.614 KB
1 Sep 2025 11.44 PM
builxejc / builxejc
0644
class-wc-privacy-exporters.php
14.691 KB
28 Jul 2021 4.11 AM
builxejc / builxejc
0644
class-wc-privacy.php
17.216 KB
23 Jun 2025 7.46 PM
builxejc / builxejc
0644
class-wc-product-attribute.php
7.868 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-product-download.php
13.178 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-product-external.php
4.984 KB
3 Mar 2025 10.28 PM
builxejc / builxejc
0644
class-wc-product-factory.php
4.588 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-product-grouped.php
6.811 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-product-query.php
2.273 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
class-wc-product-simple.php
2.7 KB
29 Jul 2025 12.34 PM
builxejc / builxejc
0644
class-wc-product-variable.php
23.764 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-product-variation.php
20.177 KB
12 May 2025 9.07 PM
builxejc / builxejc
0644
class-wc-query.php
37.013 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-rate-limiter.php
4.004 KB
1 Dec 2021 4.23 AM
builxejc / builxejc
0644
class-wc-regenerate-images-request.php
7.737 KB
25 Jan 2023 3.19 AM
builxejc / builxejc
0644
class-wc-regenerate-images.php
15.436 KB
25 Jun 2024 9.17 PM
builxejc / builxejc
0644
class-wc-register-wp-admin-settings.php
5.05 KB
22 Jun 2021 3.24 PM
builxejc / builxejc
0644
class-wc-rest-authentication.php
21.551 KB
25 Jun 2024 9.17 PM
builxejc / builxejc
0644
class-wc-rest-exception.php
0.27 KB
23 Sep 2020 1.16 AM
builxejc / builxejc
0644
class-wc-session-handler.php
24.572 KB
30 Mar 2026 5.12 PM
builxejc / builxejc
0644
class-wc-shipping-rate.php
9.342 KB
23 Jun 2025 7.46 PM
builxejc / builxejc
0644
class-wc-shipping-zone.php
13.078 KB
23 Sep 2020 1.16 AM
builxejc / builxejc
0644
class-wc-shipping-zones.php
4.995 KB
24 Nov 2025 11.10 PM
builxejc / builxejc
0644
class-wc-shipping.php
13.032 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-shortcodes.php
18.822 KB
21 Jan 2025 6.53 PM
builxejc / builxejc
0644
class-wc-structured-data.php
24.783 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-tax.php
39.871 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-wc-template-loader.php
20.421 KB
12 Nov 2025 6.35 PM
builxejc / builxejc
0644
class-wc-tracker.php
51.495 KB
6 Oct 2025 5.56 PM
builxejc / builxejc
0644
class-wc-validation.php
5.79 KB
28 May 2024 2.28 PM
builxejc / builxejc
0644
class-wc-webhook.php
30.174 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
class-woocommerce.php
63.367 KB
27 May 2026 9.54 PM
builxejc / builxejc
0644
wc-account-functions.php
14.146 KB
24 Nov 2025 11.10 PM
builxejc / builxejc
0644
wc-attribute-functions.php
21.913 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-brands-functions.php
4.17 KB
23 Sep 2024 8.44 PM
builxejc / builxejc
0644
wc-cart-functions.php
20.809 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
wc-conditional-functions.php
15.529 KB
29 Jul 2025 12.34 PM
builxejc / builxejc
0644
wc-core-functions.php
79.001 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-coupon-functions.php
5.564 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
wc-deprecated-functions.php
39.776 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
wc-formatting-functions.php
49.896 KB
24 Nov 2025 11.10 PM
builxejc / builxejc
0644
wc-interactivity-api-functions.php
2.428 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-notice-functions.php
8.492 KB
19 Jan 2026 2.46 PM
builxejc / builxejc
0644
wc-order-functions.php
43.989 KB
11 May 2026 5.17 PM
builxejc / builxejc
0644
wc-order-item-functions.php
5.032 KB
25 Jan 2023 3.19 AM
builxejc / builxejc
0644
wc-order-step-logger-functions.php
5.971 KB
23 Feb 2026 5.58 PM
builxejc / builxejc
0644
wc-page-functions.php
9.986 KB
11 May 2026 5.17 PM
builxejc / builxejc
0644
wc-product-functions.php
69.184 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-rest-functions.php
13.934 KB
24 Nov 2025 11.10 PM
builxejc / builxejc
0644
wc-stock-functions.php
17.433 KB
24 Nov 2025 11.10 PM
builxejc / builxejc
0644
wc-template-functions.php
142.513 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-template-hooks.php
12.843 KB
1 Sep 2025 11.44 PM
builxejc / builxejc
0644
wc-term-functions.php
24.628 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-update-functions.php
107.048 KB
25 May 2026 2.01 PM
builxejc / builxejc
0644
wc-user-functions.php
36.727 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-webhook-functions.php
5.912 KB
5 May 2026 2.26 PM
builxejc / builxejc
0644
wc-widget-functions.php
2.015 KB
20 Aug 2020 11.18 PM
builxejc / builxejc
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF