| 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 |
* Render the block. |
| 28 |
* |
| 29 |
* @param array $attributes Block attributes. |
| 30 |
* @return string |
| 31 |
*/ |
| 32 |
abstract public function render_block( $attributes ); |
| 33 |
|
| 34 |
/** |
| 35 |
* Check if facets should be enabled in the editor. |
| 36 |
* |
| 37 |
* @since 5.3.0 |
| 38 |
* @return boolean |
| 39 |
*/ |
| 40 |
public function is_facet_enabled_in_editor(): bool { |
| 41 |
global $pagenow; |
| 42 |
|
| 43 |
$in_editor = in_array( $pagenow, [ 'post-new.php', 'post.php' ], true ); |
| 44 |
|
| 45 |
/** |
| 46 |
* Filter if facet should be enabled in the editor. Default: false |
| 47 |
* |
| 48 |
* @hook ep_facet_enabled_in_editor |
| 49 |
* @since 5.1.0 |
| 50 |
* @param {bool} $enabled |
| 51 |
* @return {bool} If enabled or not |
| 52 |
*/ |
| 53 |
return ! ( $in_editor && ! apply_filters( 'ep_facet_enabled_in_editor', false ) ); |
| 54 |
} |
| 55 |
} |
| 56 |
|