Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created June 6, 2017 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/4592111b77675ba0dc2c9e0aea5fcbd4 to your computer and use it in GitHub Desktop.
Save jchristopher/4592111b77675ba0dc2c9e0aea5fcbd4 to your computer and use it in GitHub Desktop.
<?php
/**
* Callback for SearchWP engine choice dropdown. Swaps out engine config for
* chosen engine at runtime.
*
* @param $settings
* @param $query
*
* @return mixed
*/
function my_searchwp_engine_dropdown_handler( $settings, $query ) {
$engines = SWP()->settings['engines'];
$selected_engine = isset( $_GET['swpengine'] ) ? esc_attr( $_GET['swpengine'] ) : 'default';
if ( isset( $engines[ $selected_engine ] ) ) {
$settings = $engines[ $selected_engine ];
}
return $settings;
}
add_filter( 'searchwp_engine_settings_default', 'my_searchwp_engine_dropdown_handler', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment