From 8a07893a62b2c4210ab7d631b58a1c3ba0d3ce3c Mon Sep 17 00:00:00 2001 From: Peter Eussen Date: Mon, 20 Jul 2015 09:30:27 +0200 Subject: [PATCH 1/3] Allow users to add their own conditions to when a query should be tried or not. This allows users to circumvent any faulty plugins which cause this plugin to fail --- wp/theme/AbstractArchive.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wp/theme/AbstractArchive.php b/wp/theme/AbstractArchive.php index 4ec8b62..7e63a5f 100644 --- a/wp/theme/AbstractArchive.php +++ b/wp/theme/AbstractArchive.php @@ -19,6 +19,10 @@ function do_search($wp_query){ return; } + if ( !isset($wp_query->query) || empty($wp_query->query_vars)) { + return; + } + $this->attempted = true; $args = $this->facets($wp_query, isset($_GET['es']) ? $_GET['es'] : array()); From e554c942b53fb00d4de5d05325b821977ec03298 Mon Sep 17 00:00:00 2001 From: Peter Eussen Date: Mon, 20 Jul 2015 09:30:27 +0200 Subject: [PATCH 2/3] Allow users to add their own conditions to when a query should be tried or not. This allows users to circumvent any faulty plugins which cause this plugin to fail --- wp/theme/AbstractArchive.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/wp/theme/AbstractArchive.php b/wp/theme/AbstractArchive.php index 4ec8b62..4e5da2e 100644 --- a/wp/theme/AbstractArchive.php +++ b/wp/theme/AbstractArchive.php @@ -12,10 +12,13 @@ abstract class AbstractArchive{ function __construct(){ add_action('pre_get_posts', array(&$this, 'do_search'), 100); add_action('the_posts', array(&$this, 'process_search')); + add_filter('elasticsearch_should_query_' . $this->get_filter_name(),array($this,'filter_singular_query'),10,2); + add_filter('elasticsearch_should_query_' . $this->get_filter_name(),array($this,'filter_frontend_main_query'),20,2); } function do_search($wp_query){ - if(!$wp_query->is_main_query() || is_admin() || $this->attempted){ + + if ( !Config::apply_filters('should_query_' . $this->get_filter_name(),true,$wp_query)) { return; } @@ -75,6 +78,28 @@ function sort_posts($a, $b){ return array_search($b->ID, $this->ids) > array_search($a->ID, $this->ids) ? -1 : 1; } + + function filter_frontend_main_query($allowed,$wp_query) { + return $allowed && $wp_query->is_main_query() && !is_admin(); + } + + function filter_singular_query($allowed,$wp_query) { + return $allowed && !$this->attempted; + } + + /** + * Removes any namespaces and transforms the class name into lowercase for use in filters + * + * @return string + */ + function get_filter_name() { + $class = trim(get_class($this), '\\'); + if ($last_separator = strrpos($class, '\\')) { + $class = substr($class, $last_separator + 1); + } + return strtolower($class); + } + abstract function facets($wp_query, $existing); } ?> From 9cb9d98573708722578c803a6f445b236af96355 Mon Sep 17 00:00:00 2001 From: Peter Eussen Date: Mon, 20 Jul 2015 09:39:20 +0200 Subject: [PATCH 3/3] Remove check i needed for my site, which should not be merged into the plugin itself --- wp/theme/AbstractArchive.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wp/theme/AbstractArchive.php b/wp/theme/AbstractArchive.php index baa17c4..4e5da2e 100644 --- a/wp/theme/AbstractArchive.php +++ b/wp/theme/AbstractArchive.php @@ -22,10 +22,6 @@ function do_search($wp_query){ return; } - if ( !isset($wp_query->query) || empty($wp_query->query_vars)) { - return; - } - $this->attempted = true; $args = $this->facets($wp_query, isset($_GET['es']) ? $_GET['es'] : array());