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