Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkorthuis committed Mar 20, 2024
2 parents 75c6e4a + b1ef22a commit f5df387
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions includes/api/class-endpoint-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private function build_cache_key() {
$this->build_request_uri();
$this->set_cacheable_request_headers();
// No filter_input, see https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null/36205923.
$request_method = filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : '';
// For backwards compatibility empty string for request method = GET.
if ( 'GET' === $request_method ) {
$request_method = '';
Expand Down Expand Up @@ -263,7 +263,7 @@ public function save_cache( $result ) {
}

// No filter_input, see https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null/36205923.
$request_method = filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'GET';

// Force result to be valid JSON.
$result = json_decode( wp_json_encode( $result ) );
Expand Down Expand Up @@ -318,7 +318,8 @@ public function skip_caching() {
// Default only cache GET-requests.
$allowed_request_methods = get_option( 'wp_rest_cache_allowed_request_methods', [ 'GET' ] );
// No filter_input, see https://stackoverflow.com/questions/25232975/php-filter-inputinput-server-request-method-returns-null/36205923.
if ( ! in_array( filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ), $allowed_request_methods, true ) ) {
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'GET';
if ( ! in_array( $request_method, $allowed_request_methods, true ) ) {
return true;
}

Expand Down Expand Up @@ -458,7 +459,8 @@ public function get_api_cache() {
* @return mixed Response data.
*/
private function rest_send_cors_headers( $value ) {
$origin = get_http_origin();
$origin = get_http_origin();
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? filter_var( $_SERVER['REQUEST_METHOD'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'GET';

if ( $origin ) {
// Requests from file:// and data: URLs send "Origin: null".
Expand All @@ -469,7 +471,7 @@ private function rest_send_cors_headers( $value ) {
header( 'Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Vary: Origin', false );
} elseif ( ! headers_sent() && 'GET' === $_SERVER['REQUEST_METHOD'] ) {
} elseif ( ! headers_sent() && 'GET' === $request_method ) {
header( 'Vary: Origin' );
}

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.1.2';
$this->version = '2024.1.3';

$this->set_locale();
$this->define_admin_hooks();
Expand Down
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.5
Requires PHP: 7.0
Stable tag: 2024.1.2
Stable tag: 2024.1.3
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.1.3 =
Release Date: March 20th, 2024

Bugfix: Fix undefined array key warnings.

= 2024.1.2 =
Release Date: March 7th, 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.1.2
* Version: 2024.1.3
* Author: Acato
* Author URI: https://www.acato.nl
* Text Domain: wp-rest-cache
Expand Down

0 comments on commit f5df387

Please sign in to comment.