Event types keyed by priority. */ function vasp_event_types_by_priority() { return [ 'critical' => [ 'auth.login', 'auth.logout', 'cart.added', 'cart.removed', 'cart.updated', 'checkout.started', 'order.completed', ], 'high' => [ 'cart.coupon_applied', 'cart.coupon_removed', ], ]; } /** * Check if event tracking is enabled * * Event tracking is enabled when all conditions are true: * 1. Connected to ValueSpace (required) * 2. The canonical ValueSpace tenant configuration enables collection * 3. The site's statistics-consent policy currently permits collection * * @return bool True if event tracking should be active */ function vasp_is_event_tracking_enabled() { // Check if connected to ValueSpace $is_connected = function_exists('vasp_valuespace_is_connected') && vasp_valuespace_is_connected(); $configured = vasp_customer_event_tracking_configured(); // Respect WordPress Consent API statistics consent and the plugin filter. $has_statistics_consent = vasp_event_tracking_has_statistics_consent(); // WooCommerce is NOT required for basic event tracking (auth and commerce). return $is_connected && $configured && $has_statistics_consent; } /** Validate the bounded payload contract shared by browser and PHP producers. */ function vasp_event_validate_payload($event_type, $event_data, $url = null) { $allowed_types = []; foreach (vasp_event_types_by_priority() as $types) { $allowed_types = array_merge($allowed_types, $types); } if (!is_string($event_type) || !in_array($event_type, $allowed_types, true) || !is_array($event_data) ) { return false; } $has_bounded_cart_snapshot = in_array($event_type, [ 'cart.added', 'cart.removed', 'cart.updated', 'cart.coupon_applied', 'cart.coupon_removed', ], true) && isset($event_data['cart_snapshot']) && is_array($event_data['cart_snapshot']); $maximum_payload_bytes = $has_bounded_cart_snapshot ? 262144 : 16384; $maximum_value_count = $has_bounded_cart_snapshot ? 1024 : 250; $encoded = wp_json_encode($event_data); $value_count = 0; if (!is_string($encoded) || strlen($encoded) > $maximum_payload_bytes || !vasp_event_validate_payload_value($event_data, 0, $value_count, $maximum_value_count) ) { return false; } if ($url !== null && $url !== '' && vasp_event_normalize_page_url($url) === false) { return false; } $required = [ 'auth.login' => ['login_method'], 'auth.logout' => ['logout_method'], 'cart.added' => ['product_id', 'quantity'], 'cart.removed' => ['product_id', 'quantity'], 'cart.updated' => ['product_id', 'old_quantity', 'new_quantity'], 'checkout.started' => ['order_id'], 'order.completed' => ['order_id'], 'cart.coupon_applied' => ['coupon_present'], 'cart.coupon_removed' => ['coupon_present'], ]; foreach ($required[$event_type] as $field) { if (!array_key_exists($field, $event_data) || $event_data[$field] === '' || $event_data[$field] === null ) { return false; } } foreach (['product_id', 'order_id'] as $field) { if (isset($event_data[$field]) && !vasp_event_is_integer_value($event_data[$field], 1) ) { return false; } } foreach (['variation_id', 'customer_id'] as $field) { if (isset($event_data[$field]) && !vasp_event_is_integer_value($event_data[$field], 0) ) { return false; } } foreach (['quantity', 'old_quantity', 'new_quantity', 'item_count', 'cart_items_count'] as $field) { if (isset($event_data[$field]) && !vasp_event_is_non_negative_number($event_data[$field]) ) { return false; } } return !in_array($event_type, ['cart.added', 'cart.removed'], true) || (float) $event_data['quantity'] > 0; } /** Validate bounded primitive event data recursively. */ function vasp_event_validate_payload_value($value, $depth, &$value_count, $maximum_value_count = 250) { $value_count++; if ($value_count > (int) $maximum_value_count || $depth > 4) { return false; } if (is_string($value)) { return strlen($value) <= 2048 && preg_match('/^[^\x00-\x08\x0B\x0C\x0E-\x1F\x7F]*$/', $value) === 1; } if (is_int($value) || is_bool($value) || $value === null) { return true; } if (is_float($value)) { return is_finite($value); } if (!is_array($value) || count($value) > 100) { return false; } foreach ($value as $key => $child) { if (!is_int($key) && (!is_string($key) || strlen($key) > 64 || sanitize_key($key) !== $key) ) { return false; } if (is_string($key) && vasp_event_is_private_data_key($key)) { return false; } if (!vasp_event_validate_payload_value($child, $depth + 1, $value_count, $maximum_value_count)) { return false; } if (is_string($key) && preg_match('/(?:^|_)(?:product|order)_id$/', $key) && $child !== null && !vasp_event_is_integer_value($child, 1) ) { return false; } if (is_string($key) && in_array($key, ['quantity', 'old_quantity', 'new_quantity'], true) && !vasp_event_is_non_negative_number($child) ) { return false; } } return true; } /** Return whether an event-data key contains request or authentication data. */ function vasp_event_is_private_data_key($key) { $normalized = preg_replace('/[^a-z0-9]/', '', strtolower((string) $key)); return in_array($normalized, [ 'ip', 'ipaddress', 'remoteaddr', 'useragent', 'sessiontoken', 'wpsessiontoken', 'wpusername', ], true); } /** Return whether a scalar is a decimal integer at or above the minimum. */ function vasp_event_is_integer_value($value, $minimum) { return (is_int($value) || (is_string($value) && preg_match('/^[0-9]+$/', $value))) && (int) $value >= (int) $minimum; } /** Return whether a scalar is finite and at least zero. */ function vasp_event_is_non_negative_number($value) { return is_numeric($value) && is_finite((float) $value) && (float) $value >= 0; } /** Return whether a value is an absolute HTTP(S) URL. */ function vasp_event_is_http_url($value) { if (!is_string($value) || !filter_var($value, FILTER_VALIDATE_URL)) { return false; } return in_array( strtolower((string) wp_parse_url($value, PHP_URL_SCHEME)), ['http', 'https'], true ); } /** Sanitize and validate a same-site HTTP(S) page URL. */ function vasp_event_normalize_page_url($url) { if (!is_string($url) || $url === '' || strlen($url) > 2048) { return false; } $url = esc_url_raw($url, ['http', 'https']); if ($url === '' || !vasp_event_is_http_url($url)) { return false; } $site = wp_parse_url(home_url('/')); $candidate = wp_parse_url($url); if (!is_array($site) || !is_array($candidate) || empty($site['scheme']) || empty($site['host']) || empty($candidate['scheme']) || empty($candidate['host']) ) { return false; } $site_scheme = strtolower((string) $site['scheme']); $url_scheme = strtolower((string) $candidate['scheme']); $site_host = strtolower(rtrim((string) $site['host'], '.')); $url_host = strtolower(rtrim((string) $candidate['host'], '.')); $site_port = isset($site['port']) ? (int) $site['port'] : vasp_event_default_url_port($site_scheme); $url_port = isset($candidate['port']) ? (int) $candidate['port'] : vasp_event_default_url_port($url_scheme); if ($site_scheme !== $url_scheme || $site_host !== $url_host || $site_port !== $url_port) { return false; } $path = (string) wp_parse_url($url, PHP_URL_PATH); if ($path !== '' && preg_match('/\.(?:js|css|png|jpe?g|gif|svg|ico|woff2?|ttf|eot|pdf|zip|rar|mp3|mp4|avi)$/i', $path)) { return false; } return $url; } /** Return the standard port for a supported URL scheme. */ function vasp_event_default_url_port($scheme) { return strtolower((string) $scheme) === 'https' ? 443 : 80; } /** Return whether trusted administrator traffic must be ignored. */ function vasp_event_should_ignore_internal_traffic() { return empty(vasp_get_config('record_internal_events')); } /** * Return the canonical transient key for a raw ValueSpace event session ID. * * Session IDs are deliberately hashed in option names so identifiers are not * exposed through the options table. All readers and writers must use this * helper and retain the raw ID inside each event record. */ function vasp_event_session_transient_key($session_id) { return 'vasp_session_' . hash('sha256', (string) $session_id); } /** Return the privacy-safe transient key for page-view evidence in one session. */ function vasp_event_session_page_view_key($session_id) { return 'vasp_session_page_view_' . hash('sha256', (string) $session_id); } /** Record that the browser widget initialized on a real page for this signed session. */ function vasp_event_mark_session_page_view($session_id) { if (!wp_is_uuid($session_id, 4)) { return false; } $expiration = max(MINUTE_IN_SECONDS, (int) apply_filters( 'vasp_session_timeout', vasp_event_retention_days() * DAY_IN_SECONDS )); return vasp_set_dynamic_transient( vasp_event_session_page_view_key($session_id), time(), $expiration ); } /** Return whether this signed session has prior browser page-view evidence. */ function vasp_event_session_has_page_view($session_id) { if (!wp_is_uuid($session_id, 4)) { return false; } return (int) get_transient(vasp_event_session_page_view_key($session_id)) > 0; } /** * Read one session across the current hashed key and its legacy raw key. * * Writers call this while holding the session lock with migration enabled. A * successful migration persists one deduplicated hashed record before removing * the legacy transient, so an established session cannot appear split. * * @param string $session_id Raw event session ID. * @param bool $migrate Whether to consolidate and remove legacy storage. * @return array */ function vasp_event_read_session_events($session_id, $migrate = false) { $current_key = vasp_event_session_transient_key($session_id); $legacy_key = 'vasp_session_' . (string) $session_id; $current_events = get_transient($current_key); $legacy_events = $legacy_key !== $current_key ? get_transient($legacy_key) : false; $current_events = is_array($current_events) ? $current_events : []; $legacy_events = is_array($legacy_events) ? $legacy_events : []; $events = []; $seen = []; foreach (array_merge($legacy_events, $current_events) as $event) { if (!is_array($event)) { continue; } $uid = isset($event['event_uid']) ? (string) $event['event_uid'] : ''; $dedupe_key = $uid !== '' ? $uid : hash('sha256', wp_json_encode($event)); if (isset($seen[$dedupe_key])) { continue; } $seen[$dedupe_key] = true; $events[] = $event; } if ($migrate && !empty($legacy_events)) { $expiration = max(MINUTE_IN_SECONDS, (int) apply_filters( 'vasp_session_timeout', vasp_event_retention_days() * DAY_IN_SECONDS )); if (vasp_set_dynamic_transient($current_key, $events, $expiration)) { vasp_delete_dynamic_transient($legacy_key); } } return $events; } /** Acquire a short, database-backed lock for one event session. */ function vasp_event_acquire_session_lock($session_id, $attempts = 3) { $lock_key = 'vasp_event_session_lock_' . md5((string) $session_id); $attempts = max(1, min(5, (int) $attempts)); for ($attempt = 0; $attempt < $attempts; $attempt++) { if (add_option($lock_key, time(), '', 'no')) { return $lock_key; } $created_at = (int) get_option($lock_key, 0); if ($created_at > 0 && time() - $created_at >= 15) { delete_option($lock_key); continue; } if ($attempt + 1 < $attempts) { usleep(25000); } } return false; } /** Release a lock returned by vasp_event_acquire_session_lock(). */ function vasp_event_release_session_lock($lock_key) { if (is_string($lock_key) && $lock_key !== '') { delete_option($lock_key); } } /** * Detect known crawler, monitoring, preview, and browser-automation agents. * * This intentionally targets positive bot signatures. An empty user agent is * not treated as a bot because server-side WooCommerce hooks may not have one. * * @param string|null $user_agent User agent, or null to use the request value. * @return bool True when the request is automated. */ function vasp_event_is_bot_user_agent($user_agent = null) { if ($user_agent === null) { $user_agent = isset($_SERVER['HTTP_USER_AGENT']) && is_string($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : ''; } if ($user_agent === '') { return false; } $bot_pattern = '/(?:bot\b|crawler|spider|slurp|bingpreview|google(?:bot|other)|adsbot|mediapartners-google|yandex|baiduspider|duckduckbot|sogou|exabot|facebot|facebookexternalhit|twitterbot|linkedinbot|pinterestbot|telegrambot|whatsapp|applebot|petalbot|semrushbot|ahrefsbot|mj12bot|dotbot|bytespider|dataforseo|uptimerobot|pingdom|statuscake|newrelicpinger|headlesschrome|phantomjs|selenium|playwright|puppeteer|webdriver|lighthouse|pagespeed|gtmetrix|curl\/|wget\/|python-requests|python-urllib|axios\/|postmanruntime|go-http-client|java\/|libwww-perl)/i'; return (bool) preg_match($bot_pattern, $user_agent); } /** Return a stable HMAC for a server-issued event session identifier. */ function vasp_event_session_signature($session_id) { return hash_hmac('sha256', 'valuespace-event-session|' . (string) $session_id, wp_salt('auth')); } /** * Read or create the browser event session bound to its HttpOnly signature. * * An unsigned UUID is never adopted, including one supplied in POST data or a * caller-created cookie. Both cookies are server-only; the companion signature * proves issuance by this WordPress installation. * * @param bool $create Whether a new signed session may be issued. * @return string|null Valid UUID, or null when none exists and creation is disabled. */ function vasp_event_get_bound_session_id($create = true) { $session_cookie = 'valuespace_event_session_id'; $signature_cookie = 'valuespace_event_session_sig'; $session_id = isset($_COOKIE[$session_cookie]) && is_string($_COOKIE[$session_cookie]) ? sanitize_text_field(wp_unslash($_COOKIE[$session_cookie])) : ''; $signature = isset($_COOKIE[$signature_cookie]) && is_string($_COOKIE[$signature_cookie]) ? sanitize_text_field(wp_unslash($_COOKIE[$signature_cookie])) : ''; if (wp_is_uuid($session_id, 4) && preg_match('/^[a-f0-9]{64}$/i', $signature) && hash_equals(vasp_event_session_signature($session_id), strtolower($signature))) { return $session_id; } if (!$create) { return null; } $session_id = wp_generate_uuid4(); $signature = vasp_event_session_signature($session_id); $cookie_options = [ 'expires' => time() + (30 * DAY_IN_SECONDS), 'path' => defined('COOKIEPATH') && COOKIEPATH ? COOKIEPATH : '/', 'secure' => is_ssl(), 'httponly' => true, 'samesite' => 'Lax', ]; if (defined('COOKIE_DOMAIN') && COOKIE_DOMAIN) { $cookie_options['domain'] = COOKIE_DOMAIN; } if (!headers_sent()) { setcookie($session_cookie, $session_id, $cookie_options); setcookie($signature_cookie, $signature, $cookie_options); } $_COOKIE[$session_cookie] = $session_id; $_COOKIE[$signature_cookie] = $signature; return $session_id; } /** Return whether the request source URL has the exact configured home origin. */ function vasp_event_request_has_home_host($source_url) { if (!is_string($source_url)) { return false; } $source = wp_parse_url(trim($source_url)); $home = wp_parse_url(home_url('/')); if (!is_array($source) || !is_array($home) || empty($source['scheme']) || !in_array(strtolower($source['scheme']), ['http', 'https'], true) || empty($source['host']) || empty($home['scheme']) || empty($home['host'])) { return false; } $source_scheme = strtolower((string) $source['scheme']); $home_scheme = strtolower((string) $home['scheme']); $source_host = strtolower(rtrim((string) $source['host'], '.')); $home_host = strtolower(rtrim((string) $home['host'], '.')); $source_port = isset($source['port']) ? (int) $source['port'] : vasp_event_default_url_port($source_scheme); $home_port = isset($home['port']) ? (int) $home['port'] : vasp_event_default_url_port($home_scheme); return $source_host !== '' && hash_equals($home_scheme, $source_scheme) && hash_equals($home_host, $source_host) && $home_port === $source_port; } /** * Validate browser source metadata for anonymous event submissions. * * Origin is authoritative when supplied. Referer is used only for older * clients that omit Origin. Sec-Fetch-Site is an additional rejection signal, * not a replacement for the URL host check. */ function vasp_event_is_same_site_browser_request() { if (isset($_SERVER['HTTP_SEC_FETCH_SITE'])) { $fetch_site = is_string($_SERVER['HTTP_SEC_FETCH_SITE']) ? strtolower(sanitize_text_field(wp_unslash($_SERVER['HTTP_SEC_FETCH_SITE']))) : ''; if (!in_array($fetch_site, ['same-origin', 'same-site'], true)) { return false; } } $source_url = ''; if (!empty($_SERVER['HTTP_ORIGIN'])) { $source_url = is_string($_SERVER['HTTP_ORIGIN']) ? esc_url_raw(wp_unslash($_SERVER['HTTP_ORIGIN']), ['http', 'https']) : ''; } elseif (!empty($_SERVER['HTTP_REFERER'])) { $source_url = is_string($_SERVER['HTTP_REFERER']) ? esc_url_raw(wp_unslash($_SERVER['HTTP_REFERER']), ['http', 'https']) : ''; } return $source_url !== '' && vasp_event_request_has_home_host($source_url); } /** * Resolve the best available two-letter visitor country code. * * Trusted edge headers are preferred, followed by the logged-in customer's * WooCommerce billing country and WooCommerce's IP geolocation helper. * * @return string ISO-like alpha-2 code, or "ZZ". */ function vasp_event_country_code() { $trust_edge_headers = defined('VASP_EVENT_TRUST_GEOLOCATION_HEADERS') ? (bool) VASP_EVENT_TRUST_GEOLOCATION_HEADERS : false; $trust_edge_headers = (bool) apply_filters('vasp_event_trust_geolocation_headers', $trust_edge_headers); if ($trust_edge_headers) { foreach (['HTTP_CF_IPCOUNTRY', 'GEOIP_COUNTRY_CODE'] as $server_key) { $value = isset($_SERVER[$server_key]) && is_string($_SERVER[$server_key]) ? strtoupper(sanitize_text_field(wp_unslash($_SERVER[$server_key]))) : ''; if (preg_match('/^[A-Z]{2}$/', $value)) { return $value; } } } if (is_user_logged_in() && function_exists('WC') && WC()->customer) { $value = strtoupper((string) WC()->customer->get_billing_country()); if (preg_match('/^[A-Z]{2}$/', $value)) { return $value; } } if (class_exists('WC_Geolocation')) { $location = WC_Geolocation::geolocate_ip('', true, false); $value = isset($location['country']) ? strtoupper((string) $location['country']) : ''; if (preg_match('/^[A-Z]{2}$/', $value)) { return $value; } } return 'ZZ'; } /** * Resolve the visitor language as a normalized locale/language tag. * * @param array $event_data Sanitized client event data. * @return string Locale tag, or "unknown". */ function vasp_event_language($event_data = []) { $candidate = isset($event_data['language']) && is_string($event_data['language']) ? $event_data['language'] : ''; if ($candidate === '' && is_user_logged_in()) { $candidate = function_exists('get_user_locale') ? get_user_locale() : ''; } if ($candidate === '' && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && is_string($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $candidate = explode(',', sanitize_text_field(wp_unslash($_SERVER['HTTP_ACCEPT_LANGUAGE'])))[0]; } if ($candidate === '') { $candidate = function_exists('determine_locale') ? determine_locale() : get_locale(); } $candidate = str_replace('_', '-', sanitize_text_field($candidate)); return preg_match('/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/', $candidate) ? strtolower($candidate) : 'unknown'; } /** * Enrich a page-view payload from WordPress's canonical post/product model. * * The viewed object is the localized object. When WPML or Polylang is active, * default_* fields point at the default-language object; otherwise both sets * naturally describe the same object. * * @param array $event_data Sanitized event data. * @param string $url Validated page URL. * @return array Enriched event data. */ function vasp_event_enrich_page_data($event_data, $url) { $object_id = url_to_postid($url); if (!$object_id && function_exists('get_queried_object_id') && !wp_doing_ajax()) { $object_id = (int) get_queried_object_id(); } if (!$object_id || get_post_status($object_id) === false) { return $event_data; } $post_type = get_post_type($object_id) ?: 'post'; $is_product = $post_type === 'product'; $canonical_url = get_permalink($object_id); $default_id = $object_id; if (defined('ICL_SITEPRESS_VERSION')) { $default_language = apply_filters('wpml_default_language', null); $default_id = (int) apply_filters('wpml_object_id', $object_id, $post_type, true, $default_language); } elseif (function_exists('pll_default_language') && function_exists('pll_get_post')) { $translated_id = pll_get_post($object_id, pll_default_language('slug')); $default_id = $translated_id ? (int) $translated_id : $object_id; } $event_data['content_id'] = (int) $object_id; $event_data['content_type'] = $is_product ? 'product' : $post_type; $event_data['post_id'] = (int) $object_id; $event_data['page_id'] = (int) $object_id; $event_data['page_title'] = get_the_title($object_id); $event_data['page_url'] = $canonical_url ?: $url; if ($is_product) { $event_data['product_id'] = (int) $object_id; $event_data['product_title'] = get_the_title($object_id); $event_data['product_url'] = $canonical_url ?: $url; } $event_data['default_content_id'] = (int) $default_id; $event_data['default_title'] = get_the_title($default_id); $event_data['default_url'] = get_permalink($default_id) ?: ($canonical_url ?: $url); return $event_data; } /** * Enrich an event carrying a WooCommerce product ID. * * @param array $event_data Sanitized event data. * @return array Enriched event data. */ function vasp_event_enrich_product_data($event_data) { $product_id = (int) ($event_data['product_id'] ?? 0); if (!$product_id || get_post_type($product_id) !== 'product') { return $event_data; } $url = get_permalink($product_id); $enriched = vasp_event_enrich_page_data($event_data, $url ?: home_url('/')); $enriched['content_type'] = 'product'; $enriched['content_id'] = $product_id; $enriched['product_id'] = $product_id; $enriched['product_title'] = get_the_title($product_id); $enriched['product_url'] = $url ?: ''; return $enriched; } /** * Return true when the current request represents customer-facing site activity. * * Event storage should not capture WordPress admin usage, plugin maintenance, * catalog/image sync work, cron, REST callbacks, WP-CLI, or other background * requests. Generic browser activity is owned by the cross-site chat widget, * so this legacy gate never accepts admin-ajax as an event producer. * * @return bool True when this request can record client events. */ function vasp_is_client_event_context() { if (defined('WP_CLI') && WP_CLI) { return false; } if ((defined('DOING_CRON') && DOING_CRON) || (function_exists('wp_doing_cron') && wp_doing_cron())) { return false; } if (defined('REST_REQUEST') && REST_REQUEST) { return false; } if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) { return false; } if (vasp_event_is_bot_user_agent()) { if (function_exists('vasp_event_increment_bot_excluded')) { vasp_event_increment_bot_excluded(); } return false; } if (wp_doing_ajax()) { return false; } if (is_admin()) { return false; } return !vasp_event_should_ignore_internal_traffic() || !is_user_logged_in() || !current_user_can('manage_options'); } /** * Clear locally stored event tracking state. * * Session transients and cron health logs are runtime data. Settings are only * cleared by the full plugin reset path, not by the Events page reset. * * @param bool $include_settings Whether to clear user event tracking settings. * @return array Cleanup counters. */ function vasp_event_clear_local_state($include_settings = false) { foreach (VASP_EVENT_LEGACY_OPTIONS as $legacy_option) { delete_option($legacy_option); } delete_option(VASP_EVENT_LAST_CRON_RUN_OPTION); delete_option(VASP_EVENT_INDEX_BACKFILL_OPTION); foreach (VASP_EVENT_LEGACY_TRANSIENTS as $legacy_transient) { delete_transient($legacy_transient); } if (function_exists('vasp_event_reset_indexed_storage')) { if (!vasp_event_reset_indexed_storage()) { throw new RuntimeException('Indexed event storage could not be reset.'); } } if ($include_settings) { delete_option(VASP_EVENT_SETTINGS_OPTION); } if (function_exists('vasp_state_delete_transient_prefix')) { $transient_cleanup = function_exists('vasp_state_delete_transient_prefixes') ? vasp_state_delete_transient_prefixes(['vasp_session_', 'vasp_event_rate_']) : vasp_state_delete_transient_prefix('vasp_session_'); if (is_wp_error($transient_cleanup)) { throw new RuntimeException('Event session transient cleanup failed.'); } if (!function_exists('vasp_state_delete_transient_prefixes')) { $rate_cleanup = vasp_state_delete_transient_prefix('vasp_event_rate_'); if (is_wp_error($rate_cleanup)) { throw new RuntimeException('Event rate-limit transient cleanup failed.'); } $transient_cleanup['transients_deleted'] = (int) ($transient_cleanup['transients_deleted'] ?? 0) + (int) ($rate_cleanup['transients_deleted'] ?? 0); } } else { $transient_cleanup = ['transients_deleted' => 0]; } return [ 'event_transients_deleted' => (int) ($transient_cleanup['transients_deleted'] ?? 0), 'event_transient_database_rows_deleted' => (int) ($transient_cleanup['database_rows_deleted'] ?? 0), 'event_transient_registry_rows_deleted' => (int) ($transient_cleanup['registry_rows_deleted'] ?? 0), 'settings_deleted' => $include_settings ? 1 : 0, ]; }