PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / redirects / RedirectDeadDestinationStore.php

RedirectDeadDestinationStore.php in 404 Solution 4.3.0, at includes/redirects/RedirectDeadDestinationStore.php

56 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Stores redirect IDs whose destinations recently appeared as 404s.
9 */
10 class ABJ_404_Solution_RedirectDeadDestinationStore {
11
12 public const CACHE_KEY = 'abj404_dead_dest_ids';
13
14 /** @return array<int, string> */
15 public function getIds(): array {
16 if (!function_exists('get_transient')) {
17 return array();
18 }
19
20 $raw = get_transient(self::CACHE_KEY);
21 if (!is_array($raw)) {
22 return array();
23 }
24
25 $ids = array();
26 foreach ($raw as $value) {
27 if (is_scalar($value) && (string)$value !== '') {
28 $ids[] = (string)$value;
29 }
30 }
31
32 return array_values(array_unique($ids));
33 }
34
35 /**
36 * @param array<int, string> $ids
37 * @return void
38 */
39 public function storeIds(array $ids): void {
40 if (!function_exists('set_transient')) {
41 return;
42 }
43
44 $normalized = array();
45 foreach ($ids as $id) {
46 if (is_scalar($id) && (string)$id !== '') {
47 $normalized[] = (string)$id;
48 }
49 }
50
51 $ttl = defined('HOUR_IN_SECONDS') ? 25 * (int) HOUR_IN_SECONDS : 90000;
52 // allow-cache-empty: an empty array is the explicit "no dead destinations" cache result.
53 set_transient(self::CACHE_KEY, array_values(array_unique($normalized)), $ttl);
54 }
55 }
56