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 / engine / OldPermalinkStructureEngine.php

OldPermalinkStructureEngine.php in 404 Solution trunk, at includes/engine/OldPermalinkStructureEngine.php

65 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 * Matching engine for URLs generated by an older WordPress permalink structure.
9 */
10 class ABJ_404_Solution_OldPermalinkStructureEngine implements ABJ_404_Solution_MatchingEngine {
11
12 /** @var ABJ_404_Solution_OldPermalinkStructureResolver */
13 private $resolver;
14
15 /**
16 * @param ABJ_404_Solution_OldPermalinkStructureResolver $resolver
17 */
18 public function __construct(ABJ_404_Solution_OldPermalinkStructureResolver $resolver) {
19 $this->resolver = $resolver;
20 }
21
22 /** @return string */
23 public function getName(): string {
24 return __('old permalink structure', '404-solution');
25 }
26
27 /** @param ABJ_404_Solution_MatchRequest $request */
28 public function shouldRun(ABJ_404_Solution_MatchRequest $request): bool {
29 $options = $request->getOptions();
30 $autoRedirectsRaw = $options['auto_redirects'] ?? '0';
31 $autoRedirects = is_scalar($autoRedirectsRaw) ? (string)$autoRedirectsRaw : '0';
32 if ($autoRedirects !== '1') {
33 return false;
34 }
35
36 $enabledRaw = $options['old_permalink_structure_redirects'] ?? '1';
37 $enabled = !is_scalar($enabledRaw) || (string)$enabledRaw !== '0';
38 if (function_exists('apply_filters')) {
39 $enabled = (bool)apply_filters('abj404_old_permalink_structure_redirects_enabled', $enabled, $request);
40 }
41 if (!$enabled) {
42 return false;
43 }
44
45 return $request->getRequestedURL() !== '';
46 }
47
48 /** @param ABJ_404_Solution_MatchRequest $request */
49 public function match(ABJ_404_Solution_MatchRequest $request): ?ABJ_404_Solution_MatchResult {
50 $resolved = $this->resolver->resolve($request);
51 if ($resolved === null) {
52 return null;
53 }
54
55 return new ABJ_404_Solution_MatchResult(
56 $resolved['id'],
57 $resolved['type'],
58 $resolved['link'],
59 $resolved['title'],
60 $resolved['score'],
61 $this->getName()
62 );
63 }
64 }
65