File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
packages/smooth-backend-wordpress/src/wordpress/plugin Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -206,4 +206,22 @@ function get_preview_for_url($data)
206
206
$ fields = get_fields_recursive ($ post );
207
207
$ data ['acf ' ] = $ fields ->acf ;
208
208
return rest_ensure_response ( $ data );
209
- }, 10 , 2 );
209
+ }, 10 , 2 );
210
+
211
+ // API Caching
212
+
213
+ // Skip cache for preview
214
+ add_filter ( 'rest_cache_skip ' , function ($ skip , $ request_uri ) {
215
+ if (!$ skip && false !== stripos ( $ request_uri , 'wp-json/presspack/v1/preview ' )) {
216
+ return true ;
217
+ }
218
+
219
+ return $ skip ;
220
+ }, 10 , 2 );
221
+
222
+ // Clear cache when a post (all types) is saved
223
+ add_action ('save_post ' , function ($ post_id ) {
224
+ if (class_exists ('WP_REST_Cache ' )) {
225
+ WP_REST_Cache::empty_cache ();
226
+ }
227
+ });
You can’t perform that action at this time.
0 commit comments