diff --git a/includes/api/class-endpoint-api.php b/includes/api/class-endpoint-api.php index e4fac00..453c72b 100644 --- a/includes/api/class-endpoint-api.php +++ b/includes/api/class-endpoint-api.php @@ -11,6 +11,8 @@ namespace WP_Rest_Cache_Plugin\Includes\API; +use WP_Rest_Cache_Plugin\Includes\Util; + /** * API for endpoint caching. * @@ -95,7 +97,7 @@ private function build_request_uri() { // No filter_input, see https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null/36205923. $request_uri = filter_var( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ); // Remove home_url from request_uri for uri's with WordPress in a subdir (like /wp). - $request_uri = str_replace( get_home_url(), '', $request_uri ); + $request_uri = str_replace( Util::get_home_url(), '', $request_uri ); if ( '//' === substr( $request_uri, 0, 2 ) ) { $request_uri = substr( $request_uri, 1 ); } diff --git a/includes/api/class-oembed-api.php b/includes/api/class-oembed-api.php index f00980b..3f3aec3 100644 --- a/includes/api/class-oembed-api.php +++ b/includes/api/class-oembed-api.php @@ -11,6 +11,8 @@ namespace WP_Rest_Cache_Plugin\Includes\API; +use WP_Rest_Cache_Plugin\Includes\Util; + /** * Caching of the Oembed endpoint. * @@ -129,7 +131,7 @@ private function get_oembed_post_id( $uri ) { if ( isset( $uri_parts['query'] ) && ! empty( $uri_parts['query'] ) ) { parse_str( $uri_parts['query'], $params ); if ( isset( $params['url'] ) ) { - $post_id = url_to_postid( get_home_url() . $params['url'] ); + $post_id = url_to_postid( Util::get_home_url() . $params['url'] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $post_id = apply_filters( 'oembed_request_post_id', $post_id, $params['url'] ); diff --git a/includes/caching/class-caching.php b/includes/caching/class-caching.php index cf5bd54..37cff9d 100644 --- a/includes/caching/class-caching.php +++ b/includes/caching/class-caching.php @@ -11,6 +11,8 @@ namespace WP_Rest_Cache_Plugin\Includes\Caching; +use WP_Rest_Cache_Plugin\Includes\Util; + /** * Class responsible for caching and saving cache relations. * @@ -1192,7 +1194,7 @@ public function regenerate_expired_caches() { foreach ( $results as &$result ) { if ( 1 === strtotime( $result['expiration'] ) || false === get_transient( $this->transient_key( $result['cache_key'] ) ) ) { // Regenerate. - $url = get_home_url() . $result['request_uri']; + $url = Util::get_home_url() . $result['request_uri']; $return = wp_remote_get( $url, [ diff --git a/includes/class-activator.php b/includes/class-activator.php index 0e9da6d..8658560 100644 --- a/includes/class-activator.php +++ b/includes/class-activator.php @@ -68,7 +68,7 @@ public static function create_mu_plugin() { } // No filter_input, see https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null/36205923. $request_uri = filter_var( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ); - $url = get_home_url() . $request_uri; + $url = Util::get_home_url() . $request_uri; $creds = request_filesystem_credentials( $url ); if ( ! WP_Filesystem( $creds ) ) { return; diff --git a/includes/class-plugin.php b/includes/class-plugin.php index e2d0d03..88f723e 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -55,7 +55,7 @@ class Plugin { */ public function __construct() { $this->plugin_name = 'wp-rest-cache'; - $this->version = '2024.2.1'; + $this->version = '2024.2.2'; $this->set_locale(); $this->define_admin_hooks(); diff --git a/includes/class-util.php b/includes/class-util.php new file mode 100644 index 0000000..39104c8 --- /dev/null +++ b/includes/class-util.php @@ -0,0 +1,35 @@ + + */ +class Util { + + /** + * Get the home url, without converting it to the current language. + * + * @return string The home url. + */ + public static function get_home_url() { + add_filter( 'wpml_skip_convert_url_string', '__return_true' ); + $home_url = get_home_url(); + remove_filter( 'wpml_skip_convert_url_string', '__return_true' ); + return $home_url; + } +} diff --git a/readme.txt b/readme.txt index 60322a9..3710bfd 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: cache, wp-rest-api, api, rest, rest cache Requires at least: 4.7 Tested up to: 6.6 Requires PHP: 7.0 -Stable tag: 2024.2.1 +Stable tag: 2024.2.2 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl.html @@ -171,6 +171,11 @@ Yes you can! Use the `wp wp-rest-cache flush` command to flush caches. Type `wp == Changelog == += 2024.2.2 = +Release Date: September 9th, 2024 + +Bugfix: Fix incorrect building of endpoint URL when using WPML. + = 2024.2.1 = Release Date: August 28th, 2024 diff --git a/wp-rest-cache.php b/wp-rest-cache.php index db2fcb7..9ff981e 100644 --- a/wp-rest-cache.php +++ b/wp-rest-cache.php @@ -10,7 +10,7 @@ * Plugin Name: WP REST Cache * Plugin URI: https://www.acato.nl * Description: Adds caching to the WP REST API - * Version: 2024.2.1 + * Version: 2024.2.2 * Author: Acato * Author URI: https://www.acato.nl * Text Domain: wp-rest-cache