PluginProbe
404 Solution / trunk
404 Solution vtrunk
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 / admin / RedirectDestinationWarningPolicy.php

RedirectDestinationWarningPolicy.php in 404 Solution trunk, at includes/admin/RedirectDestinationWarningPolicy.php

54 lines 2.0 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 * Decides which destination warning, if any, a redirect table row should show.
9 */
10 class ABJ_404_Solution_RedirectDestinationWarningPolicy {
11
12 /**
13 * @param array<string, mixed> $row
14 * @param mixed $rowType
15 * @param string $rowFinalDest
16 * @param string $destForView
17 * @param bool $destinationIsMissing
18 * @param array<mixed> $deadDestIds
19 * @return array{exists: string, notExists: string, text: string, destForView: string}
20 */
21 public function resolve(array $row, $rowType, string $rowFinalDest, string $destForView,
22 bool $destinationIsMissing, array $deadDestIds): array {
23 $exists = '';
24 $notExists = 'display: none;';
25 $text = __("This page doesn't exist or is not published so the redirect won't work.", '404-solution');
26
27 if ($destinationIsMissing) {
28 $exists = 'display: none;';
29 $notExists = '';
30 $text = __('Destination missing. Edit this redirect and choose a destination.', '404-solution');
31 if (trim((string)$destForView) === '') {
32 $destForView = __('(Destination missing)', '404-solution');
33 }
34 }
35
36 if (array_key_exists('published_status', $row) && $row['published_status'] == '0') {
37 $exists = 'display: none;';
38 $notExists = '';
39 if (trim((string)$destForView) === '') {
40 $destForView = __('(Destination unavailable)', '404-solution');
41 }
42 }
43
44 $rowIdStr = is_scalar($row['id'] ?? '') ? (string)($row['id'] ?? '') : '';
45 if (in_array($rowIdStr, $deadDestIds, true)) {
46 $exists = 'display: none;';
47 $notExists = '';
48 $text = __('Destination returned 404 recently, redirect suspended until destination is restored.', '404-solution');
49 }
50
51 return array('exists' => $exists, 'notExists' => $notExists, 'text' => $text, 'destForView' => $destForView);
52 }
53 }
54