Ticket #21688: 21688-4.patch
| File 21688-4.patch, 3.7 KB (added by azaozz, 10 months ago) |
|---|
-
wp-includes/default-filters.php
192 192 add_filter( 'editable_slug', 'urldecode' ); 193 193 add_filter( 'editable_slug', 'esc_textarea' ); 194 194 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); 195 add_filter( 'wp_search_stopwords', 'wp_search_stopwords' ); 195 196 196 197 // Actions 197 198 add_action( 'wp_head', 'wp_enqueue_scripts', 1 ); -
wp-includes/functions.php
3637 3637 return true; 3638 3638 } 3639 3639 3640 /** 3641 * Common stopwords (terms) that are excluded from the separate term matching when searching for posts. 3642 * The list of English stopwords is the approximate search engines list. MySQL has a much longer default list of full-text stopwords. 3643 * 3644 * @since 3.5.0 3645 * @param array optional Terms to exclude when searching 3646 * 3647 * @return array 3648 */ 3649 function wp_search_stopwords( $in = array() ) { 3650 $_words = explode( ',', _x('about,are,com,for,from,how,that,the,this,was,what,when,where,who,will,with,www', 'Comma separated list of common words to exclude when searching.') ); 3651 $words = array(); 3652 3653 foreach( $_words as $word ) { 3654 $word = trim($word, "\r\n\t "); 3655 if ( !$word ) 3656 continue; 3657 $words[] = $word; 3658 } 3659 3660 return array_merge( $in, $words ); 3661 } 3662 -
wp-includes/query.php
2173 2173 } 2174 2174 } 2175 2175 2176 // If a search pattern is specified, load the posts that match 2177 if ( !empty($q['s']) ) { 2176 // If a search pattern is specified, load the posts that match. 2177 // Sanity check: search string shouldn't be more than 1600 characters. 2178 // See ticket #21688 for more info. 2179 if ( !empty($q['s']) && strlen($q['s']) < 1600 ) { 2178 2180 // added slashes screw with quote grouping when done early, so done later 2179 2181 $q['s'] = stripslashes($q['s']); 2180 2182 if ( empty( $_GET['s'] ) && $this->is_main_query() ) … … 2183 2185 $q['search_terms'] = array($q['s']); 2184 2186 } else { 2185 2187 preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches); 2186 $q['search_terms'] = array_map('_search_terms_tidy', $matches[0]); 2188 $_search_terms = array_map('_search_terms_tidy', $matches[0]); 2189 $q['search_terms'] = array(); 2190 $stopwords = apply_filters_ref_array( 'wp_search_stopwords', array( array(), &$this ) ); 2191 $strtolower_func = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; 2192 2193 foreach ( (array) $_search_terms as $term ) { 2194 if ( empty( $term{2} ) || in_array( $strtolower_func($term), $stopwords, true ) ) 2195 continue; 2196 $q['search_terms'][] = $term; 2197 } 2198 2199 unset($_search_terms); 2200 // if the search string has only short terms or stopwords, or is more than 10 terms long, match it as sentence 2201 if ( empty($q['search_terms']) || count($q['search_terms']) > 10 ) 2202 $q['search_terms'] = array($q['s']); 2187 2203 } 2204 2188 2205 $n = !empty($q['exact']) ? '' : '%'; 2189 2206 $searchand = ''; 2190 foreach( (array)$q['search_terms'] as $term ) {2207 foreach( $q['search_terms'] as $term ) { 2191 2208 $term = esc_sql( like_escape( $term ) ); 2192 2209 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))"; 2193 2210 $searchand = ' AND ';