| 1 |
<?php |
| 2 |
|
| 3 |
namespace passster; |
| 4 |
|
| 5 |
/** |
| 6 |
* REST controller for the "protected_areas" post type. |
| 7 |
* |
| 8 |
* WordPress' default WP_REST_Posts_Controller ignores a post type's |
| 9 |
* public/publicly_queryable flags when deciding read access — it only |
| 10 |
* checks show_in_rest and post status — so with the default controller |
| 11 |
* anyone could read every area's protected content via /wp/v2/protected_areas. |
| 12 |
* These routes exist only so the block editor (logged-in admins) can |
| 13 |
* read/write areas; visitors unlock areas exclusively through the |
| 14 |
* password-gated passster/v1 routes. |
| 15 |
*/ |
| 16 |
class PS_Protected_Areas_Rest_Controller extends \WP_REST_Posts_Controller { |
| 17 |
|
| 18 |
/** |
| 19 |
* Checks if a given request has access to read protected areas. |
| 20 |
* |
| 21 |
* @param \WP_REST_Request $request Full details about the request. |
| 22 |
* |
| 23 |
* @return bool |
| 24 |
*/ |
| 25 |
public function get_items_permissions_check( $request ) { |
| 26 |
return current_user_can( apply_filters( 'passster_user_capability', 'manage_options' ) ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Checks if a given request has access to read a single protected area. |
| 31 |
* |
| 32 |
* @param \WP_REST_Request $request Full details about the request. |
| 33 |
* |
| 34 |
* @return bool |
| 35 |
*/ |
| 36 |
public function get_item_permissions_check( $request ) { |
| 37 |
return current_user_can( apply_filters( 'passster_user_capability', 'manage_options' ) ); |
| 38 |
} |
| 39 |
} |
| 40 |
|