Endpoint.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\API\Endpoints\Logs; |
| 4 | |
| 5 | use Give\API\RestRoute; |
| 6 | use WP_Error; |
| 7 | |
| 8 | /** |
| 9 | * Class Endpoint |
| 10 | * @package GiveDivi\Divi\Routes |
| 11 | * |
| 12 | * @since 2.10.0 |
| 13 | */ |
| 14 | abstract class Endpoint implements RestRoute |
| 15 | { |
| 16 | |
| 17 | /** |
| 18 | * @var string |
| 19 | */ |
| 20 | protected $endpoint; |
| 21 | |
| 22 | /** |
| 23 | * Check user permissions |
| 24 | * @return bool|WP_Error |
| 25 | */ |
| 26 | public function permissionsCheck() |
| 27 | { |
| 28 | if ( ! current_user_can('edit_posts')) { |
| 29 | return new WP_Error( |
| 30 | 'rest_forbidden', |
| 31 | esc_html__('You dont have the right permissions to view Logs', 'give'), |
| 32 | ['status' => $this->authorizationStatusCode()] |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | // Sets up the proper HTTP status code for authorization. |
| 40 | public function authorizationStatusCode() |
| 41 | { |
| 42 | if (is_user_logged_in()) { |
| 43 | return 403; |
| 44 | } |
| 45 | |
| 46 | return 401; |
| 47 | } |
| 48 | } |
| 49 |