| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace cx_newsletter;
- use \wp_rest_request;
- trait rest_endpoint_with_apikey {
- protected function check_apikey(string $key) : bool {
- $valid_apikey = (
- $this
- ->get_settings()
- ->get('apikey')
- );
- return $key === $valid_apikey;
- }
- protected function check_request_apikey(wp_rest_request $request) : bool {
- $params = $request->get_query_params();
- if (!array_key_exists('apikey', $params)) {
- return false;
- }
- return $this->check_apikey($params['apikey']);
- }
- protected function bad_apikey_response() : array {
- $response = new response_builder();
-
- return $response
- ->set_code(response_code::APIKEY_FAIL)
- ->set_status(response_status::ERROR)
- ->set_message('Api Key is not valid, or not specified in the params.')
- ->build();
- }
- }
|