@@ -44,6 +44,9 @@ public function __construct() {
44
44
45
45
// Clean up null entries from the response
46
46
add_filter ( 'rest_pre_echo_response ' , array ( $ this , 'clean_types_response ' ), 10 , 3 );
47
+
48
+ // Clear cache after each request to make the endpoint stateless
49
+ add_action ( 'rest_request_after_callbacks ' , array ( $ this , 'clear_cache_for_types_request ' ), 10 , 1 );
47
50
}
48
51
49
52
/**
@@ -74,7 +77,7 @@ public function filter_types_request( $response, $handler, $request ) {
74
77
return $ response ;
75
78
}
76
79
77
- // Get post types, calculating once and reusing for the entire request
80
+ // Get post types with caching within this single request
78
81
if ( null === $ this ->cached_post_types ) {
79
82
$ this ->cached_post_types = $ this ->get_source_post_types ( $ source );
80
83
}
@@ -118,6 +121,7 @@ public function filter_post_type( $response, $post_type, $request ) {
118
121
return $ response ;
119
122
}
120
123
124
+ // Get post types with caching within this single request
121
125
if ( null === $ this ->cached_post_types ) {
122
126
$ this ->cached_post_types = $ this ->get_source_post_types ( $ source );
123
127
}
@@ -391,4 +395,17 @@ function ( $entry ) {
391
395
392
396
return $ response ;
393
397
}
398
+
399
+ /**
400
+ * Clear cache for types endpoint requests to prevent cross-contamination
401
+ *
402
+ * @since SCF 6.5.0
403
+ *
404
+ * @param mixed $response The current response.
405
+ */
406
+ public function clear_cache_for_types_request ( $ response ) {
407
+ // Clear cache to prevent cross-contamination and make the endpoint stateless
408
+ $ this ->cached_post_types = null ;
409
+ return $ response ;
410
+ }
394
411
}
0 commit comments