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