@@ -42,8 +42,8 @@ class Admin implements WpHooksInterface
4242 public function __construct ()
4343 {
4444 $ this ->settings = new Settings ([
45- Settings::LENGTH => 1 ,
46- Settings::PERIOD => WEEK_IN_SECONDS ,
45+ Settings::LENGTH => 10 ,
46+ Settings::PERIOD => MINUTE_IN_SECONDS ,
4747 ]);
4848 }
4949
@@ -52,15 +52,15 @@ public function __construct()
5252 */
5353 public function addHooks ()
5454 {
55- if (\apply_filters ( self :: FILTER_SHOW_ADMIN , true )) {
56- if (\apply_filters ( self :: FILTER_SHOW_ADMIN_MENU , true )) {
55+ if ($ this -> showAdmin ( )) {
56+ if ($ this -> showAdminMenu ( )) {
5757 $ this ->addAction ('admin_menu ' , [$ this , 'adminMenu ' ]);
5858 } else {
5959 $ this ->addAction ('admin_action_ ' . self ::ADMIN_ACTION , [$ this , 'adminAction ' ]);
6060 $ this ->addAction ('admin_notices ' , [$ this , 'adminNotices ' ]);
6161 }
6262
63- if (\apply_filters ( self :: FILTER_SHOW_ADMIN_BAR_MENU , true )) {
63+ if ($ this -> showAdminMenuBar ( )) {
6464 $ this ->addAction ('admin_bar_menu ' , [$ this , 'adminBarMenu ' ], 999 );
6565 }
6666 }
@@ -69,7 +69,7 @@ public function addHooks()
6969 /**
7070 * Hook into the WordPress admin menu.
7171 */
72- public function adminMenu ()
72+ protected function adminMenu ()
7373 {
7474 \add_submenu_page (
7575 'options-general.php ' ,
@@ -86,7 +86,7 @@ public function adminMenu()
8686 *
8787 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar object.
8888 */
89- public function adminBarMenu (WP_Admin_Bar $ wp_admin_bar )
89+ protected function adminBarMenu (WP_Admin_Bar $ wp_admin_bar )
9090 {
9191 $ args = [
9292 'id ' => WpRestApiCache::ID ,
@@ -105,7 +105,7 @@ public function adminBarMenu(WP_Admin_Bar $wp_admin_bar)
105105 /**
106106 * Helper to check the request action.
107107 */
108- public function adminAction ()
108+ protected function adminAction ()
109109 {
110110 $ this ->requestCallback ();
111111
@@ -127,7 +127,7 @@ public function adminAction()
127127 /**
128128 * Maybe add an admin notice.
129129 */
130- public function adminNotices ()
130+ protected function adminNotices ()
131131 {
132132 if (! empty ($ _REQUEST [self ::NONCE_NAME ]) &&
133133 \wp_verify_nonce ($ _REQUEST [self ::NONCE_NAME ], self ::NONCE_ACTION ) &&
@@ -142,10 +142,10 @@ public function adminNotices()
142142 /**
143143 * Render the admin settings page.
144144 */
145- public function renderPage ()
145+ protected function renderPage ()
146146 {
147147 $ this ->requestCallback ();
148- require_once \dirname (__FILE__ ) . '../../views/settings.php ' ;
148+ require_once \dirname (__FILE__ ) . '/ ../../views/settings.php ' ;
149149 }
150150
151151 /**
@@ -154,7 +154,7 @@ public function renderPage()
154154 * @param null|string $key Option key value.
155155 * @return mixed
156156 */
157- public function getOptions ($ key = null )
157+ protected function getOptions ($ key = null )
158158 {
159159 $ options = \apply_filters (
160160 self ::FILTER_CACHE_OPTIONS ,
@@ -177,7 +177,7 @@ private function requestCallback()
177177 $ message = \esc_html__ ('Nothing to see here. ' , 'wp-rest-api-cache ' );
178178
179179 if (! empty ($ _REQUEST [self ::NONCE_NAME ]) &&
180- \wp_verify_nonce ($ _REQUEST [self ::NONCE_NAME ], 'rest_cache_options ' )
180+ \wp_verify_nonce ($ _REQUEST [self ::NONCE_NAME ], 'rest_cache_options ' ) !== false
181181 ) {
182182 if (! empty ($ _GET ['rest_cache_empty ' ]) &&
183183 filter_var_int ($ _GET ['rest_cache_empty ' ]) === 1
@@ -197,7 +197,7 @@ private function requestCallback()
197197 * @param \WP_User The current user.
198198 */
199199 \do_action (self ::ACTION_REQUEST_FLUSH_CACHE , $ message , $ type , \wp_get_current_user ());
200- } elseif (isset ( $ _POST [ ' rest_cache_options ' ]) && ! empty ($ _POST [' rest_cache_options ' ])) {
200+ } elseif (! empty ($ _POST [self :: OPTION_KEY ])) {
201201 if ($ this ->updateOptions ($ _POST ['rest_cache_options ' ])) {
202202 $ type = 'updated ' ;
203203 $ message = \esc_html__ ('The cache time has been updated ' , 'wp-rest-api-cache ' );
@@ -218,12 +218,10 @@ private function requestCallback()
218218 */
219219 private function updateOptions (array $ options ) : bool
220220 {
221- $ options = \array_map (
222- 'sanitize_text_field ' ,
223- \apply_filters (self ::FILTER_CACHE_UPDATE_OPTIONS , $ options )
224- );
221+ $ this ->settings ->setLength (absint ($ options [Settings::EXPIRATION ][Settings::LENGTH ]));
222+ $ this ->settings ->setPeriod (absint ($ options [Settings::EXPIRATION ][Settings::PERIOD ]));
225223
226- return \update_option (self ::OPTION_KEY , $ options , 'yes ' );
224+ return \update_option (self ::OPTION_KEY , $ this -> settings -> getExpiration () , 'yes ' );
227225 }
228226
229227 /**
@@ -233,7 +231,7 @@ private function updateOptions(array $options) : bool
233231 */
234232 private function getEmptyCacheUrl () : string
235233 {
236- if (\apply_filters ( self :: FILTER_SHOW_ADMIN_MENU , true )) {
234+ if ($ this -> showAdminMenu ( )) {
237235 return \wp_nonce_url (
238236 \add_query_arg (
239237 [
@@ -259,4 +257,31 @@ private function getEmptyCacheUrl() : string
259257 self ::NONCE_NAME
260258 );
261259 }
260+
261+ /**
262+ * Should the admin functions be shown?
263+ * @return bool
264+ */
265+ private function showAdmin () : bool
266+ {
267+ return \apply_filters (self ::FILTER_SHOW_ADMIN , true ) === true ;
268+ }
269+
270+ /**
271+ * Show the admin menu be shown?
272+ * @return bool
273+ */
274+ private function showAdminMenu () : bool
275+ {
276+ return \apply_filters (self ::FILTER_SHOW_ADMIN_MENU , true ) === true ;
277+ }
278+
279+ /**
280+ * Show the admin menu bar be shown?
281+ * @return bool
282+ */
283+ private function showAdminMenuBar () : bool
284+ {
285+ return \apply_filters (self ::FILTER_SHOW_ADMIN_BAR_MENU , true ) === true ;
286+ }
262287}
0 commit comments