From 2fb90c5602875b001836b1564a93b1c5993c5aff Mon Sep 17 00:00:00 2001 From: JiveDig Date: Fri, 29 Dec 2023 10:46:55 -0500 Subject: [PATCH] Adds filter for facet the block editor for posts For https://github.com/10up/ElasticPress/issues/3775 --- includes/classes/Feature/Facets/Facets.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/includes/classes/Feature/Facets/Facets.php b/includes/classes/Feature/Facets/Facets.php index 7e7ee46e77..ba237b2e82 100644 --- a/includes/classes/Feature/Facets/Facets.php +++ b/includes/classes/Feature/Facets/Facets.php @@ -111,12 +111,23 @@ public function __construct() { public function setup() { global $pagenow; - // This feature should not run while in the editor. - if ( in_array( $pagenow, [ 'post-new.php', 'post.php' ], true ) ) { - return; - } - foreach ( $this->types as $type => $class ) { + /** + * Filter if facet should be enabled in the editor. + * + * @hook ep_facet_enabled_in_editor + * @since TBD + * @param {bool} $enabled If enabled + * @param {string} $type The facet type + * @return {bool} If enabled or not + */ + $enabled = apply_filters( 'ep_facet_enabled_in_editor', false, $type ); + + // Skip if this feature should not run while in the post editor. + if ( in_array( $pagenow, [ 'post-new.php', 'post.php' ], true ) && ! $enabled ) { + continue; + } + $this->types[ $type ]->setup(); }