From 9d77c2c8eefa101b6b1db5af6789a7799d66947f Mon Sep 17 00:00:00 2001 From: ramonjd Date: Sat, 4 Dec 2021 14:46:46 +1100 Subject: [PATCH 1/2] Testing whether changing to the pre_site_transient_filter fixes the PHP unit tests, reflecting the change in wordpress/develop 54499 --- phpunit/class-wp-rest-url-details-controller-test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit/class-wp-rest-url-details-controller-test.php b/phpunit/class-wp-rest-url-details-controller-test.php index 901e83052356e..2801044f68921 100644 --- a/phpunit/class-wp-rest-url-details-controller-test.php +++ b/phpunit/class-wp-rest-url-details-controller-test.php @@ -277,11 +277,11 @@ function( $args, $url ) { public function test_will_return_from_cache_if_populated() { $transient_name = 'g_url_details_response_' . md5( static::$url_placeholder ); - remove_filter( "pre_transient_{$transient_name}", '__return_null' ); + remove_filter( "pre_site_transient_{$transient_name}", '__return_null' ); // Force cache to return a known value as the remote URL http response body. add_filter( - "pre_transient_{$transient_name}", + "pre_site_transient_{$transient_name}", function() { return 'This value from cache.'; } @@ -301,7 +301,7 @@ function() { // Data should be that from cache not from mocked network response. $this->assertContains( 'This value from cache', $data['title'] ); - remove_all_filters( "pre_transient_{$transient_name}" ); + remove_all_filters( "pre_site_transient_{$transient_name}" ); } public function test_allows_filtering_data_retrieved_for_a_given_url() { From 2dd8c274b12c3c85c21e6294f2f7eab5af44bd40 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Sun, 5 Dec 2021 14:51:34 +0400 Subject: [PATCH 2/2] Use global transients --- lib/class-wp-rest-url-details-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/class-wp-rest-url-details-controller.php b/lib/class-wp-rest-url-details-controller.php index 69fc1bb984765..e0482f8f0fe60 100644 --- a/lib/class-wp-rest-url-details-controller.php +++ b/lib/class-wp-rest-url-details-controller.php @@ -383,7 +383,7 @@ private function build_cache_key_for_url( $url ) { * @return mixed The value from the cache. */ private function get_cache( $key ) { - return get_transient( $key ); + return get_site_transient( $key ); } /** @@ -406,7 +406,7 @@ private function set_cache( $key, $data = '' ) { */ $cache_expiration = apply_filters( 'rest_url_details_cache_expiration', $ttl ); - return set_transient( $key, $data, $cache_expiration ); + return set_site_transient( $key, $data, $cache_expiration ); } /**