From 0d35f3bbbf06e31f267a51c415848b1dfafdc5eb Mon Sep 17 00:00:00 2001 From: prcdevgitbot Date: Wed, 9 Oct 2024 20:16:32 +0000 Subject: [PATCH] See https://github.com/pewresearch/prc-platform/commit/a065e3f8c94c9dc57cd1696fdd7ae03e8b41aedf from refs/tags/v1.0.x-beta --- includes/facets/class-facets.php | 13 +++++++++---- .../facets/providers/facet-wp/class-facetwp-api.php | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/facets/class-facets.php b/includes/facets/class-facets.php index 9a63962..3d3d057 100644 --- a/includes/facets/class-facets.php +++ b/includes/facets/class-facets.php @@ -20,10 +20,13 @@ class Facets { private $version; /** - * Initialize the EP Facets class. + * Current Site ID */ - protected $ep_facets; + private $site_id; + /** + * The unique identifier of this plugin. + */ public static $handle = 'prc-platform-facets'; /** @@ -33,6 +36,7 @@ class Facets { */ public function __construct( $version, $loader ) { $this->version = $version; + $this->site_id = get_current_blog_id(); // Include middleware for FacetWP and ElasticPress. require_once plugin_dir_path( __FILE__ ) . 'providers/facet-wp/class-facetwp-middleware.php'; @@ -41,6 +45,7 @@ public function __construct( $version, $loader ) { // Include block files. $this->load_blocks(); + // Initialize hybrid facets system. $this->init($loader); } @@ -82,7 +87,7 @@ public static function format_label($label) { * @return string */ public static function construct_cache_key($query = [], $selected = []) { - $invalidate = '10/05/2024b'; + $invalidate = '10/09/2024b'; // Remove pagination from the query args $query = array_merge($query, array( 'paged' => 1 @@ -110,7 +115,7 @@ public static function construct_cache_group() { } public function init($loader = null) { - if ( null !== $loader ) { + if ( null !== $loader && $this->site_id === PRC_PRIMARY_SITE_ID ) { // FacetWP Back Compat: // We need to determine when to load these middlewares. If it's a search page, lets use EP, otherwise use FacetWP. new FacetWP_Middleware($loader); diff --git a/includes/facets/providers/facet-wp/class-facetwp-api.php b/includes/facets/providers/facet-wp/class-facetwp-api.php index 112c312..53a12a1 100644 --- a/includes/facets/providers/facet-wp/class-facetwp-api.php +++ b/includes/facets/providers/facet-wp/class-facetwp-api.php @@ -99,7 +99,7 @@ protected function process_taxonomy_facet($facet) { continue; } $taxonomy_facet['choices'][] = [ - 'count' => $facet_obj['count'], + 'count' => isset($facet_obj['count']) ? $facet_obj['count'] : 0, 'label' => \PRC\Platform\Facets::format_label($facet_obj['label']), 'slug' => $facet_obj['value'], 'facetSlug' => $facet_slug, @@ -156,7 +156,7 @@ protected function process_non_taxonomy_facet($facet) { } foreach ($facet['choices'] as $facet_obj) { $standard_facet['choices'][] = [ - 'count' => $facet_obj['count'], + 'count' => isset($facet_obj['count']) ? $facet_obj['count'] : 0, 'label' => \PRC\Platform\Facets::format_label($facet_obj['label']), 'slug' => $facet_obj['value'], 'facetSlug' => $facet_slug,