@@ -36,7 +36,6 @@ class RestDispatch implements WpHooksInterface
3636 const FILTER_CACHE_EXPIRE = WpRestApiCache::FILTER_PREFIX . 'expire ' ;
3737 const FILTER_CACHE_HEADERS = WpRestApiCache::FILTER_PREFIX . 'headers ' ;
3838 const FILTER_CACHE_SKIP = WpRestApiCache::FILTER_PREFIX . 'skip ' ;
39- const FILTER_CACHE_BYPASS = WpRestApiCache::FILTER_PREFIX . 'bypass ' ;
4039 const HEADER_CACHE_CONTROL = 'Cache-Control ' ;
4140 const QUERY_CACHE_DELETE = 'rest_cache_delete ' ;
4241 const QUERY_CACHE_FORCE_DELETE = 'rest_force_delete ' ;
@@ -57,8 +56,11 @@ class RestDispatch implements WpHooksInterface
5756 */
5857 public function addHooks ()
5958 {
60- $ this ->addFilter ('rest_pre_dispatch ' , [$ this , 'preDispatch ' ], 10 , 3 );
61- $ this ->addFilter ('rest_post_dispatch ' , [$ this , 'postDispatch ' ], 10 , 3 );
59+ $ options = $ this ->getOptions ([]);
60+ if (!isset ($ options [Settings::BYPASS ]) || $ options [Settings::BYPASS ] !== 'on ' ) {
61+ $ this ->addFilter ('rest_pre_dispatch ' , [$ this , 'preDispatch ' ], 10 , 3 );
62+ $ this ->addFilter ('rest_post_dispatch ' , [$ this , 'postDispatch ' ], 10 , 3 );
63+ }
6264 }
6365
6466 /**
@@ -73,7 +75,7 @@ public function addHooks()
7375 */
7476 protected function preDispatch ($ result , WP_REST_Server $ server , WP_REST_Request $ request )
7577 {
76- if ($ result !== null || \apply_filters ( self :: FILTER_CACHE_BYPASS , false ) === true ) {
78+ if ($ result !== null ) {
7779 return $ result ;
7880 }
7981 $ request_uri = $ this ->getRequestUri ();
@@ -230,7 +232,7 @@ protected function getCachedResult(
230232 Settings::PERIOD => MINUTE_IN_SECONDS ,
231233 ],
232234 ];
233- $ options = \get_option (Admin:: OPTION_KEY , $ defaults );
235+ $ options = $ this -> getOptions ( $ defaults );
234236 /**
235237 * Filter for cache expiration time.
236238 * @param int Expiration time.
@@ -367,4 +369,14 @@ private function isUserAuthenticated(WP_REST_Request $request) : bool
367369 */
368370 return \apply_filters (self ::FILTER_CACHE_VALIDATE_AUTH , false , $ request ) !== false ;
369371 }
372+
373+ /**
374+ * Get the options.
375+ * @param mixed $defaults
376+ * @return mixed
377+ */
378+ private function getOptions ($ defaults )
379+ {
380+ return \get_option (Admin::OPTION_KEY , $ defaults );
381+ }
370382}
0 commit comments