Permalink
Browse files

Implement latest Nice Search

  • Loading branch information...
1 parent 8000e5c commit 6ae15813aaa56d4a82522f89992d3a03aa8e06fa @retlehs retlehs committed Dec 26, 2012
Showing with 8 additions and 17 deletions.
  1. +8 −17 lib/cleanup.php
View
@@ -476,28 +476,19 @@ function roots_widget_first_last_classes($params) {
* @link http://txfx.net/wordpress-plugins/nice-search/
*/
function roots_nice_search_redirect() {
- if (is_search() && strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === false && strpos($_SERVER['REQUEST_URI'], '/search/') === false) {
- wp_redirect(home_url('/search/' . str_replace(array(' ', '%20'), array('+', '+'), urlencode(get_query_var('s')))), 301);
- exit();
+ global $wp_rewrite;
+ if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) {
+ return;
}
-}
-add_action('template_redirect', 'roots_nice_search_redirect');
-
-/**
- * Fix for get_search_query() returning +'s between search terms
- */
-function roots_search_query($escaped = true) {
- $query = apply_filters('roots_search_query', get_query_var('s'));
-
- if ($escaped) {
- $query = esc_attr($query);
+ $search_base = $wp_rewrite->search_base;
+ if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {
+ wp_redirect(home_url("/{$search_base}/" . urlencode(get_query_var('s'))));
+ exit();
}
-
- return urldecode($query);
}
-add_filter('get_search_query', 'roots_search_query');
+add_action('template_redirect', 'roots_nice_search_redirect');
/**
* Fix for empty search queries redirecting to home page

0 comments on commit 6ae1581

Please sign in to comment.