| 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 |
* @var string |
| 18 |
*/ |
| 19 |
protected $endpoint; |
| 20 |
|
| 21 |
/** |
| 22 |
* Check user permissions |
| 23 |
* @return bool|WP_Error |
| 24 |
*/ |
| 25 |
public function permissionsCheck() { |
| 26 |
if ( ! current_user_can( 'edit_posts' ) ) { |
| 27 |
return new WP_Error( |
| 28 |
'rest_forbidden', |
| 29 |
esc_html__( 'You dont have the right permissions to view Logs', 'give' ), |
| 30 |
[ 'status' => $this->authorizationStatusCode() ] |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
return true; |
| 35 |
} |
| 36 |
|
| 37 |
// Sets up the proper HTTP status code for authorization. |
| 38 |
public function authorizationStatusCode() { |
| 39 |
if ( is_user_logged_in() ) { |
| 40 |
return 403; |
| 41 |
} |
| 42 |
|
| 43 |
return 401; |
| 44 |
} |
| 45 |
} |
| 46 |
|