Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkorthuis committed Sep 9, 2024
2 parents 44f5e28 + d38dc29 commit 77ce2f4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 7 deletions.
4 changes: 3 additions & 1 deletion includes/api/class-endpoint-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace WP_Rest_Cache_Plugin\Includes\API;

use WP_Rest_Cache_Plugin\Includes\Util;

/**
* API for endpoint caching.
*
Expand Down Expand Up @@ -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 );
}
Expand Down
4 changes: 3 additions & 1 deletion includes/api/class-oembed-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace WP_Rest_Cache_Plugin\Includes\API;

use WP_Rest_Cache_Plugin\Includes\Util;

/**
* Caching of the Oembed endpoint.
*
Expand Down Expand Up @@ -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'] );
Expand Down
4 changes: 3 additions & 1 deletion includes/caching/class-caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
[
Expand Down
2 changes: 1 addition & 1 deletion includes/class-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion includes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
35 changes: 35 additions & 0 deletions includes/class-util.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Util functions for usage throughout the plugin.
*
* @link: https://www.acato.nl
*
* @package WP_Rest_Cache_Plugin
* @subpackage WP_Rest_Cache_Plugin/Includes
*/

namespace WP_Rest_Cache_Plugin\Includes;

/**
* Util functions for usage throughout the plugin.
*
* This class define util functions that can be used throughout the plugin.
*
* @package WP_Rest_Cache_Plugin
* @subpackage WP_Rest_Cache_Plugin/Includes
* @author Richard Korthuis - Acato <[email protected]>
*/
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;
}
}
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion wp-rest-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77ce2f4

Please sign in to comment.