| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abstract Facet Block class. |
| 4 |
* |
| 5 |
* @since 4.7.0 |
| 6 |
* @package elasticpress |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace ElasticPress\Feature\Facets; |
| 10 |
|
| 11 |
/** |
| 12 |
* Abstract Facet Block class. |
| 13 |
*/ |
| 14 |
abstract class Block { |
| 15 |
|
| 16 |
/** |
| 17 |
* Setup hooks and filters for facet block. |
| 18 |
*/ |
| 19 |
abstract public function setup(); |
| 20 |
|
| 21 |
/** |
| 22 |
* Register facet block. |
| 23 |
*/ |
| 24 |
abstract public function register_block(); |
| 25 |
|
| 26 |
/** |
| 27 |
* Setup REST endpoints for facet feature. |
| 28 |
*/ |
| 29 |
abstract public function setup_endpoints(); |
| 30 |
|
| 31 |
/** |
| 32 |
* Render the block. |
| 33 |
* |
| 34 |
* @param array $attributes Block attributes. |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
abstract public function render_block( $attributes ); |
| 38 |
|
| 39 |
/** |
| 40 |
* Outputs the block preview |
| 41 |
* |
| 42 |
* @param \WP_REST_Request $request REST request |
| 43 |
* @return string |
| 44 |
*/ |
| 45 |
abstract public function render_block_preview( $request ); |
| 46 |
|
| 47 |
/** |
| 48 |
* Check if the current user has permission to view the facets REST endpoint. |
| 49 |
* |
| 50 |
* @return true|\WP_Error |
| 51 |
*/ |
| 52 |
public function check_facets_rest_permission() { |
| 53 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
| 54 |
return new \WP_Error( 'ep_rest_forbidden', esc_html__( 'Sorry, you cannot view this resource.', 'elasticpress' ), array( 'status' => 401 ) ); |
| 55 |
} |
| 56 |
return true; |
| 57 |
} |
| 58 |
} |
| 59 |
|