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