|
| 1 | +From f5661aa133190dc1b877740c02572ed5f75fd23b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Marc del Amo < [email protected]> |
| 3 | +Date: Thu, 11 Jul 2024 16:02:02 +0200 |
| 4 | +Subject: [PATCH] fix: yoast regex redirects not working with wpml |
| 5 | + |
| 6 | +--- |
| 7 | + classes/class-wpml-wpseo-redirection.php | 14 ++++++++++++-- |
| 8 | + 1 file changed, 12 insertions(+), 2 deletions(-) |
| 9 | + |
| 10 | +diff --git a/classes/class-wpml-wpseo-redirection.php b/classes/class-wpml-wpseo-redirection.php |
| 11 | +index 2c7940358..47801af12 100644 |
| 12 | +--- a/classes/class-wpml-wpseo-redirection.php |
| 13 | ++++ b/classes/class-wpml-wpseo-redirection.php |
| 14 | +@@ -32,8 +32,18 @@ class WPML_WPSEO_Redirection { |
| 15 | + } |
| 16 | + |
| 17 | + foreach ( $redirections as $redirection ) { |
| 18 | +- if ( $redirection['origin'] === $url || '/' . $redirection['origin'] === $url ) { |
| 19 | +- return true; |
| 20 | ++ if($redirection['format'] == 'regex'){ |
| 21 | ++ // Ensure $url starts with /, if regex would need to check if string starts with this is needed. |
| 22 | ++ if(strpos($url, '/', 0) !== 0){ |
| 23 | ++ $url = '/' . $url; |
| 24 | ++ } |
| 25 | ++ // Lets use ~ as a regex delimiter instead of /, as we are matching a URL. |
| 26 | ++ preg_match('~' . $redirection['origin'] . '~', $url, $matches); |
| 27 | ++ if(count($matches) > 0){ |
| 28 | ++ return true; |
| 29 | ++ } |
| 30 | ++ } else if($redirection['origin'] === $url || '/' . $redirection['origin'] === $url){ |
| 31 | ++ return true; |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | +-- |
| 36 | +2.24.4 |
| 37 | + |
0 commit comments