From 49ff111d81b4ca73d9624d3cc594491d42566cc0 Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Fri, 17 Oct 2025 10:02:47 +0200 Subject: [PATCH] Fixed: filter rest_url to remove language subdir from data-api. --- src/Compatibility.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Compatibility.php b/src/Compatibility.php index 5a5a125..398371b 100644 --- a/src/Compatibility.php +++ b/src/Compatibility.php @@ -43,6 +43,11 @@ public function __construct() { add_filter( 'sgo_javascript_combine_excluded_external_paths', [ $this, 'exclude_plausible_js' ] ); } + // TranslatePress + if ( defined( 'TRP_PLUGIN_VERSION' ) ) { + add_filter( 'rest_url', [ $this, 'multilingual_compatibility' ], 10, 1 ); + } + // W3 Total Cache if ( defined( 'W3TC_VERSION' ) ) { add_filter( 'w3tc_minify_js_script_tags', [ $this, 'unset_plausible_js' ] ); @@ -50,7 +55,7 @@ public function __construct() { // WPML if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { - add_filter( 'rest_url', [ $this, 'wpml_compatibility' ], 10, 1 ); + add_filter( 'rest_url', [ $this, 'multilingual_compatibility' ], 10, 1 ); } // WP Optimize @@ -188,15 +193,19 @@ public function exclude_js_by_handle( $excluded_handles ) { } /** - * WPML overrides the REST API URL to include the language 'subdirectory', which leads to 404s. - * This forces it back to default behavior. + * Multilingual plugins, e.g., TranslatePress and WPML, override the REST API URL to include + * the language 'subdirectory', which leads to 404 errors. + * + * This filter forces it back to default behavior. + * + * @filter rest_url * * @param mixed $url * * @return string|void * @throws Exception */ - public function wpml_compatibility( $url ) { + public function multilingual_compatibility( $url ) { $rest_endpoint = Helpers::get_rest_endpoint( false ); if ( strpos( $url, $rest_endpoint ) !== false ) {