Skip to content

Commit

Permalink
Moved load_seamless_mode()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaydsouza committed Nov 20, 2024
1 parent 6537bfc commit 68b5866
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 0 additions & 18 deletions includes/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand All @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions includes/frontend/class-template-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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
Expand Down

0 comments on commit 68b5866

Please sign in to comment.