(int) $expires_at ) { self::revoke_token(); return false; } $incoming_hash = self::hash_token( $token_from_url ); return hash_equals( $stored_hash, $incoming_hash ); } /** * Removes the active support token from the database. */ public static function revoke_token(): void { delete_option( self::OPTION_HASH ); delete_option( self::OPTION_RAW ); delete_option( self::OPTION_EXPIRES ); delete_option( self::OPTION_NOTE ); } /** * Fetches information about the active support token. * * @return array|null Array with ['expires_at' => int, 'note' => string, 'token' => string] or null. */ public static function get_token_info(): ?array { $expires_at = get_option( self::OPTION_EXPIRES ); if ( empty( $expires_at ) ) { return null; } if ( time() > (int) $expires_at ) { self::revoke_token(); return null; } $note = get_option( self::OPTION_NOTE ); $raw_token = get_option( self::OPTION_RAW ); return [ 'expires_at' => (int) $expires_at, 'note' => (string) $note, 'token' => (string) $raw_token, ]; } /** * Private helper function to hash a token with the WP Salt. * * @param string $token The raw token. * * @return string The SHA256 HMAC Hash. */ private static function hash_token( string $token ): string { return hash_hmac( 'sha256', $token, AUTH_SALT ); } }