Skip to content

Commit e4eabe5

Browse files
committed
Add the method for permission callback instead of closure
1 parent cb42aff commit e4eabe5

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

plugins/optimization-detective/storage/class-od-rest-url-metrics-store-endpoint.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,28 @@ public function get_registration_args(): array {
100100
rest_get_endpoint_args_for_schema( OD_Strict_URL_Metric::get_json_schema() )
101101
),
102102
'callback' => array( $this, 'handle_rest_request' ),
103-
'permission_callback' => static function () {
104-
// Needs to be available to unauthenticated visitors.
105-
if ( OD_Storage_Lock::is_locked() ) {
106-
return new WP_Error(
107-
'url_metric_storage_locked',
108-
__( 'URL Metric storage is presently locked for the current IP.', 'optimization-detective' ),
109-
array( 'status' => 423 )
110-
);
111-
}
112-
return true;
113-
},
103+
'permission_callback' => array( $this, 'permission_callback' ),
114104
);
115105
}
116106

107+
/**
108+
* Permission callback for the REST API endpoint.
109+
*
110+
* @return true|WP_Error True if the request has permission, WP_Error object otherwise.
111+
*/
112+
public function permission_callback() {
113+
114+
// Needs to be available to unauthenticated visitors.
115+
if ( OD_Storage_Lock::is_locked() ) {
116+
return new WP_Error(
117+
'url_metric_storage_locked',
118+
__( 'URL Metric storage is presently locked for the current IP.', 'optimization-detective' ),
119+
array( 'status' => 423 )
120+
);
121+
}
122+
return true;
123+
}
124+
117125
/**
118126
* Determines if the HTTP origin is an authorized one.
119127
*

0 commit comments

Comments
 (0)