diff --git a/includes/class-main.php b/includes/class-main.php index 780d829..fb24e05 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -162,7 +162,6 @@ private function init() { public function hooks() { add_action( 'init', array( $this, 'initiate_plugin' ) ); add_action( 'widgets_init', array( $this, 'register_widgets' ) ); - add_action( 'parse_query', array( $this, 'load_seamless_mode' ) ); add_action( 'activated_plugin', array( $this, 'activated_plugin' ), 10, 2 ); add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) ); @@ -187,23 +186,6 @@ public function register_widgets() { register_widget( '\\WebberZone\\Better_Search\\Frontend\\Widgets\\Search_Heatmap' ); } - /** - * Load seamless mode and hook into WP_Query to check if better_search_query is set and true. - * If so, load the Better Search query. - * - * @since 3.3.0 - * - * @param \WP_Query $query Query object. - */ - public function load_seamless_mode( $query ) { - if ( ( $query->is_search() && wp_is_block_theme() ) || true === $query->get( 'better_search_query' ) ) { - if ( ! isset( $query->query_vars['is_better_search_loaded'] ) || ! $query->query_vars['is_better_search_loaded'] ) { - new \Better_Search_Core_Query( $query->query_vars ); - $query->set( 'is_better_search_loaded', true ); - } - } - } - /** * Checks if another version of Better Search/Better Search Pro is active and deactivates it. * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated. diff --git a/includes/frontend/class-template-handler.php b/includes/frontend/class-template-handler.php index ff05458..89b1283 100644 --- a/includes/frontend/class-template-handler.php +++ b/includes/frontend/class-template-handler.php @@ -26,6 +26,7 @@ class Template_Handler { * @since 4.0.0 */ public function __construct() { + add_action( 'parse_query', array( $this, 'load_seamless_mode' ) ); add_filter( 'template_include', array( $this, 'template_include' ) ); add_action( 'init', array( $this, 'register_patterns' ) ); add_filter( 'get_block_templates', array( $this, 'manage_block_templates' ), 10, 3 ); @@ -38,6 +39,23 @@ public function __construct() { } } + /** + * Load seamless mode and hook into WP_Query to check if better_search_query is set and true. + * If so, load the Better Search query. + * + * @since 4.0.0 + * + * @param \WP_Query $query Query object. + */ + public function load_seamless_mode( $query ) { + if ( ( $query->is_search() && wp_is_block_theme() ) || true === $query->get( 'better_search_query' ) ) { + if ( ! isset( $query->query_vars['is_better_search_loaded'] ) || ! $query->query_vars['is_better_search_loaded'] ) { + new \Better_Search_Core_Query( $query->query_vars ); + $query->set( 'is_better_search_loaded', true ); + } + } + } + /** * Displays the search results * First checks if the theme contains a search template and uses that