Plugin Directory

Changeset 3444552


Ignore:
Timestamp:
01/22/2026 05:55:32 AM (4 weeks ago)
Author:
aaron13100
Message:
  • Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
Location:
404-solution
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • 404-solution/tags/3.1.10/404-solution.php

    r3443087 r3444552  
    88    Author URI:  https://www.ajexperience.com/404-solution/
    99
    10     Version: 3.1.9
     10    Version: 3.1.10
    1111    Requires at least: 5.0
    1212    Requires PHP: 7.4
  • 404-solution/tags/3.1.10/CHANGELOG.md

    r3443087 r3444552  
    11# Changelog #
     2
     3## Version 3.1.10 (Jan 21, 2026) ##
     4* Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
    25
    36## Version 3.1.9 (Jan 20, 2026) ##
  • 404-solution/tags/3.1.10/README.md

    r3443087 r3444552  
    8181## Changelog ##
    8282
     83## Version 3.1.10 (Jan 21, 2026) ##
     84* Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
     85
    8386## Version 3.1.9 (Jan 20, 2026) ##
    8487* FIX: Manual and external redirects now store and match Unicode paths consistently.
  • 404-solution/tags/3.1.10/includes/PluginLogic.php

    r3443087 r3444552  
    421421        }
    422422
     423        if ($translated === null || $translated === '') {
     424            $translated = $this->wpmlRedirectUrl($location, $requestedURL);
     425            if ($translated !== null && $translated !== '') {
     426                $location = $translated;
     427            }
     428        }
     429
     430        if ($translated === null || $translated === '') {
     431            $translated = $this->polylangRedirectUrl($location, $requestedURL);
     432            if ($translated !== null && $translated !== '') {
     433                $location = $translated;
     434            }
     435        }
     436
    423437        // Allow other multilingual plugins/themes to override redirect destinations.
    424438        return apply_filters('abj404_translate_redirect_url', $location, $requestedURL);
     
    483497        if (function_exists('trp_get_current_language')) {
    484498            $language = trp_get_current_language();
     499            if (is_string($language) && $language !== '') {
     500                return $language;
     501            }
     502        }
     503
     504        return '';
     505    }
     506
     507    private function wpmlRedirectUrl($location, $requestedURL) {
     508        if (!$this->wpmlIntegrationAvailable()) {
     509            return null;
     510        }
     511
     512        if (!$this->isLocalUrl($location)) {
     513            return null;
     514        }
     515
     516        $language = $this->getWpmlLanguageFromRequest($requestedURL);
     517        if ($language === '') {
     518            return null;
     519        }
     520
     521        $translated = $this->wpmlTranslateUrl($location, $language);
     522        if (!is_string($translated) || $translated === '' || $translated === $location) {
     523            return null;
     524        }
     525
     526        if (!$this->isLocalUrl($translated)) {
     527            return null;
     528        }
     529
     530        return $translated;
     531    }
     532
     533    private function wpmlIntegrationAvailable() {
     534        return function_exists('wpml_current_language') ||
     535            has_filter('wpml_current_language') ||
     536            has_filter('wpml_language_from_url') ||
     537            has_filter('wpml_permalink');
     538    }
     539
     540    private function wpmlTranslateUrl($url, $language) {
     541        if (has_filter('wpml_permalink')) {
     542            return apply_filters('wpml_permalink', $url, $language);
     543        }
     544
     545        return null;
     546    }
     547
     548    private function getWpmlLanguageFromRequest($requestedURL) {
     549        $fullRequestedUrl = $this->buildFullUrlFromRequest($requestedURL);
     550
     551        if (has_filter('wpml_language_from_url')) {
     552            $language = apply_filters('wpml_language_from_url', '', $fullRequestedUrl);
     553            if (is_string($language) && $language !== '') {
     554                return $language;
     555            }
     556        }
     557
     558        if (function_exists('wpml_current_language')) {
     559            $language = wpml_current_language();
     560            if (is_string($language) && $language !== '') {
     561                return $language;
     562            }
     563        }
     564
     565        if (has_filter('wpml_current_language')) {
     566            $language = apply_filters('wpml_current_language', null);
     567            if (is_string($language) && $language !== '') {
     568                return $language;
     569            }
     570        }
     571
     572        return '';
     573    }
     574
     575    private function polylangRedirectUrl($location, $requestedURL) {
     576        if (!$this->polylangIntegrationAvailable()) {
     577            return null;
     578        }
     579
     580        if (!$this->isLocalUrl($location)) {
     581            return null;
     582        }
     583
     584        $language = $this->getPolylangLanguageFromRequest($requestedURL);
     585        if ($language === '') {
     586            return null;
     587        }
     588
     589        $translated = $this->polylangTranslateUrl($location, $language);
     590        if (!is_string($translated) || $translated === '' || $translated === $location) {
     591            return null;
     592        }
     593
     594        if (!$this->isLocalUrl($translated)) {
     595            return null;
     596        }
     597
     598        return $translated;
     599    }
     600
     601    private function polylangIntegrationAvailable() {
     602        return function_exists('pll_current_language') ||
     603            function_exists('pll_translate_url');
     604    }
     605
     606    private function polylangTranslateUrl($url, $language) {
     607        if (function_exists('pll_translate_url')) {
     608            return pll_translate_url($url, $language);
     609        }
     610
     611        return null;
     612    }
     613
     614    private function getPolylangLanguageFromRequest($requestedURL) {
     615        if (function_exists('pll_current_language')) {
     616            $language = pll_current_language();
    485617            if (is_string($language) && $language !== '') {
    486618                return $language;
  • 404-solution/tags/3.1.10/readme.txt

    r3443087 r3444552  
    66Requires PHP: 7.4
    77Tested up to: 6.9
    8 Stable tag: 3.1.9
     8Stable tag: 3.1.10
    99License: GPL-3.0-or-later
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3838* **Debug logging** to troubleshoot redirect behavior
    3939* **Performance optimized** for sites with 10,000+ pages
     40* **Multilingual-friendly redirects** (TranslatePress, WPML, Polylang) to keep redirects in the request language
    4041
    4142= How It Works =
     
    111112**Important:** For very high-traffic sites with thousands of simultaneous users, disable "Create automatic redirects" and don't use the shortcode to ensure optimal performance.
    112113
     114= Does it work with WPML or Polylang? =
     115
     116Yes. 404 Solution keeps redirects in the same language as the request when WPML or Polylang is active. TranslatePress is also supported. Language is detected using the multilingual plugin’s URL/language APIs, and the matched redirect destination is translated to that language without changing the matching logic.
     117
    113118= Does it work with WooCommerce? =
    114119
     
    237242
    238243== Changelog ==
     244
     245= Version 3.1.10 (Jan 21, 2026) =
     246* Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
    239247
    240248= Version 3.1.9 (Jan 20, 2026) =
  • 404-solution/trunk/404-solution.php

    r3443087 r3444552  
    88    Author URI:  https://www.ajexperience.com/404-solution/
    99
    10     Version: 3.1.9
     10    Version: 3.1.10
    1111    Requires at least: 5.0
    1212    Requires PHP: 7.4
  • 404-solution/trunk/CHANGELOG.md

    r3443087 r3444552  
    11# Changelog #
     2
     3## Version 3.1.10 (Jan 21, 2026) ##
     4* Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
    25
    36## Version 3.1.9 (Jan 20, 2026) ##
  • 404-solution/trunk/README.md

    r3443087 r3444552  
    8181## Changelog ##
    8282
     83## Version 3.1.10 (Jan 21, 2026) ##
     84* Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
     85
    8386## Version 3.1.9 (Jan 20, 2026) ##
    8487* FIX: Manual and external redirects now store and match Unicode paths consistently.
  • 404-solution/trunk/includes/PluginLogic.php

    r3443087 r3444552  
    421421        }
    422422
     423        if ($translated === null || $translated === '') {
     424            $translated = $this->wpmlRedirectUrl($location, $requestedURL);
     425            if ($translated !== null && $translated !== '') {
     426                $location = $translated;
     427            }
     428        }
     429
     430        if ($translated === null || $translated === '') {
     431            $translated = $this->polylangRedirectUrl($location, $requestedURL);
     432            if ($translated !== null && $translated !== '') {
     433                $location = $translated;
     434            }
     435        }
     436
    423437        // Allow other multilingual plugins/themes to override redirect destinations.
    424438        return apply_filters('abj404_translate_redirect_url', $location, $requestedURL);
     
    483497        if (function_exists('trp_get_current_language')) {
    484498            $language = trp_get_current_language();
     499            if (is_string($language) && $language !== '') {
     500                return $language;
     501            }
     502        }
     503
     504        return '';
     505    }
     506
     507    private function wpmlRedirectUrl($location, $requestedURL) {
     508        if (!$this->wpmlIntegrationAvailable()) {
     509            return null;
     510        }
     511
     512        if (!$this->isLocalUrl($location)) {
     513            return null;
     514        }
     515
     516        $language = $this->getWpmlLanguageFromRequest($requestedURL);
     517        if ($language === '') {
     518            return null;
     519        }
     520
     521        $translated = $this->wpmlTranslateUrl($location, $language);
     522        if (!is_string($translated) || $translated === '' || $translated === $location) {
     523            return null;
     524        }
     525
     526        if (!$this->isLocalUrl($translated)) {
     527            return null;
     528        }
     529
     530        return $translated;
     531    }
     532
     533    private function wpmlIntegrationAvailable() {
     534        return function_exists('wpml_current_language') ||
     535            has_filter('wpml_current_language') ||
     536            has_filter('wpml_language_from_url') ||
     537            has_filter('wpml_permalink');
     538    }
     539
     540    private function wpmlTranslateUrl($url, $language) {
     541        if (has_filter('wpml_permalink')) {
     542            return apply_filters('wpml_permalink', $url, $language);
     543        }
     544
     545        return null;
     546    }
     547
     548    private function getWpmlLanguageFromRequest($requestedURL) {
     549        $fullRequestedUrl = $this->buildFullUrlFromRequest($requestedURL);
     550
     551        if (has_filter('wpml_language_from_url')) {
     552            $language = apply_filters('wpml_language_from_url', '', $fullRequestedUrl);
     553            if (is_string($language) && $language !== '') {
     554                return $language;
     555            }
     556        }
     557
     558        if (function_exists('wpml_current_language')) {
     559            $language = wpml_current_language();
     560            if (is_string($language) && $language !== '') {
     561                return $language;
     562            }
     563        }
     564
     565        if (has_filter('wpml_current_language')) {
     566            $language = apply_filters('wpml_current_language', null);
     567            if (is_string($language) && $language !== '') {
     568                return $language;
     569            }
     570        }
     571
     572        return '';
     573    }
     574
     575    private function polylangRedirectUrl($location, $requestedURL) {
     576        if (!$this->polylangIntegrationAvailable()) {
     577            return null;
     578        }
     579
     580        if (!$this->isLocalUrl($location)) {
     581            return null;
     582        }
     583
     584        $language = $this->getPolylangLanguageFromRequest($requestedURL);
     585        if ($language === '') {
     586            return null;
     587        }
     588
     589        $translated = $this->polylangTranslateUrl($location, $language);
     590        if (!is_string($translated) || $translated === '' || $translated === $location) {
     591            return null;
     592        }
     593
     594        if (!$this->isLocalUrl($translated)) {
     595            return null;
     596        }
     597
     598        return $translated;
     599    }
     600
     601    private function polylangIntegrationAvailable() {
     602        return function_exists('pll_current_language') ||
     603            function_exists('pll_translate_url');
     604    }
     605
     606    private function polylangTranslateUrl($url, $language) {
     607        if (function_exists('pll_translate_url')) {
     608            return pll_translate_url($url, $language);
     609        }
     610
     611        return null;
     612    }
     613
     614    private function getPolylangLanguageFromRequest($requestedURL) {
     615        if (function_exists('pll_current_language')) {
     616            $language = pll_current_language();
    485617            if (is_string($language) && $language !== '') {
    486618                return $language;
  • 404-solution/trunk/readme.txt

    r3443087 r3444552  
    66Requires PHP: 7.4
    77Tested up to: 6.9
    8 Stable tag: 3.1.9
     8Stable tag: 3.1.10
    99License: GPL-3.0-or-later
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3838* **Debug logging** to troubleshoot redirect behavior
    3939* **Performance optimized** for sites with 10,000+ pages
     40* **Multilingual-friendly redirects** (TranslatePress, WPML, Polylang) to keep redirects in the request language
    4041
    4142= How It Works =
     
    111112**Important:** For very high-traffic sites with thousands of simultaneous users, disable "Create automatic redirects" and don't use the shortcode to ensure optimal performance.
    112113
     114= Does it work with WPML or Polylang? =
     115
     116Yes. 404 Solution keeps redirects in the same language as the request when WPML or Polylang is active. TranslatePress is also supported. Language is detected using the multilingual plugin’s URL/language APIs, and the matched redirect destination is translated to that language without changing the matching logic.
     117
    113118= Does it work with WooCommerce? =
    114119
     
    237242
    238243== Changelog ==
     244
     245= Version 3.1.10 (Jan 21, 2026) =
     246* Improvement: Add WPML and Polylang-aware redirect translation based on the request language.
    239247
    240248= Version 3.1.9 (Jan 20, 2026) =
Note: See TracChangeset for help on using the changeset viewer.