*/ public function read(): array { try { if (!function_exists('get_option')) { return array(); } $raw = ABJ_404_Solution_OptionShapeRead::scalar(self::OPTION_NAME, ''); if ($raw === '') { return array(); } if (!is_string($raw)) { abj404_logPhpFallback('canonical-hook-census', 'canonical hook census option has a malformed non-string value. Recovery: delete the ' . self::OPTION_NAME . ' option and retry from a front-end 404.'); return array(); } $decoded = json_decode($raw, true); if (!is_array($decoded)) { abj404_logPhpFallback('canonical-hook-census', 'canonical hook census option contains malformed JSON: ' . json_last_error_msg() . '. Recovery: delete the ' . self::OPTION_NAME . ' option and retry from a front-end 404.'); return array(); } $record = array(); foreach ($decoded as $key => $value) { if (!is_string($key)) { abj404_logPhpFallback('canonical-hook-census', 'canonical hook census option contains a non-string field name. Recovery: delete the ' . self::OPTION_NAME . ' option and retry from a front-end 404.'); return array(); } $record[$key] = $value; } return $record; } catch (Throwable $e) { abj404_logPhpFallback('canonical-hook-census', 'canonical hook census read failed (code ' . $e->getCode() . '): ' . $e->getMessage()); return array(); } } /** @param array $record */ public function write(array $record): void { if (!function_exists('update_option')) { return; } // encode() reports the JSON error on the durable WARN channel itself. $encoded = ABJ_404_Solution_Utf8SafeRecord::encode($record, 'canonical hook census'); if ($encoded === '') { return; } if (!update_option(self::OPTION_NAME, $encoded, false)) { abj404_logPhpFallback('canonical-hook-census', 'canonical hook census option write was not persisted. Recovery: inspect the WordPress ' . 'options table and object-cache error logs, then retry from a front-end 404.'); } } /** Drop cached values that can hide a concurrent refresh. */ public function refreshReads(): void { if (!function_exists('wp_cache_delete')) { return; } wp_cache_delete(self::OPTION_NAME, 'options'); wp_cache_delete('notoptions', 'options'); } }