DonationActions.php
5 months ago
Endpoint.php
5 months ago
ListDonations.php
8 months ago
ListDonationsStats.php
9 months ago
SwitchDonationView.php
4 years ago
Endpoint.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Donations\Endpoints; |
| 4 | |
| 5 | use Give\API\RestRoute; |
| 6 | use Give\Framework\Permissions\Facades\UserPermissions; |
| 7 | use WP_Error; |
| 8 | |
| 9 | abstract class Endpoint implements RestRoute |
| 10 | { |
| 11 | /** |
| 12 | * @var string |
| 13 | */ |
| 14 | protected $endpoint; |
| 15 | |
| 16 | /** |
| 17 | * @param string $value |
| 18 | * @since 2.20.0 |
| 19 | * |
| 20 | * @return bool |
| 21 | */ |
| 22 | public function validateInt($value) |
| 23 | { |
| 24 | return filter_var($value, FILTER_VALIDATE_INT); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Check user permissions |
| 29 | * @since 4.14.0 update permission capability to use facade |
| 30 | * @since 4.3.1 update permissions |
| 31 | * @since 2.20.0 |
| 32 | * |
| 33 | * @return bool|WP_Error |
| 34 | */ |
| 35 | public function permissionsCheck() |
| 36 | { |
| 37 | if (UserPermissions::donations()->canView()) { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | return new WP_Error( |
| 42 | 'rest_forbidden', |
| 43 | __("You don't have permission to view Donations", 'give'), |
| 44 | ['status' => $this->authorizationStatusCode()] |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Sets up the proper HTTP status code for authorization. |
| 50 | * @since 2.20.0 |
| 51 | * |
| 52 | * @return int |
| 53 | */ |
| 54 | public function authorizationStatusCode() |
| 55 | { |
| 56 | if (is_user_logged_in()) { |
| 57 | return 403; |
| 58 | } |
| 59 | |
| 60 | return 401; |
| 61 | } |
| 62 | } |
| 63 |