File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,14 +108,7 @@ function () use ( $ns, $version ) {
108108 [
109109 'methods ' => 'GET ' ,
110110 'callback ' => [ $ this , 'get_scans_stats ' ],
111- 'permission_callback ' => function ( $ request ) {
112- if ( Connector::validate_jwt_token_in_request_with_fallback ( $ request ) ) {
113- // Only allow if the site is still registered (site_id present).
114- $ site_id = (string ) get_option ( 'edac_site_id ' , '' );
115- return '' !== $ site_id ;
116- }
117- return current_user_can ( 'edit_posts ' );
118- },
111+ 'permission_callback ' => [ $ this , 'can_get_scans_stats ' ],
119112 ]
120113 );
121114 }
@@ -365,6 +358,23 @@ function () use ( $ns, $version ) {
365358 );
366359 }
367360
361+ /**
362+ * Determine whether the current request may access the scans stats endpoint.
363+ *
364+ * @param \WP_REST_Request $request REST request.
365+ *
366+ * @return bool
367+ */
368+ public function can_get_scans_stats ( \WP_REST_Request $ request ): bool {
369+ if ( Connector::validate_jwt_token_in_request_with_fallback ( $ request ) ) {
370+ // Only allow if the site is still registered (site_id present).
371+ $ site_id = (string ) get_option ( 'edac_site_id ' , '' );
372+ return '' !== $ site_id ;
373+ }
374+
375+ return current_user_can ( 'edit_posts ' );
376+ }
377+
368378 /**
369379 * REST handler to clear issues results for a given post ID.
370380 *
You can’t perform that action at this time.
0 commit comments