Replace all uses of like_escape() with $wpdb->esc_like().

Props miqrogroove.
See #10041.

Built from https://develop.svn.wordpress.org/trunk@28712


git-svn-id: http://core.svn.wordpress.org/trunk@28528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor
2014-06-10 00:44:15 +00:00
parent 82bdc78500
commit 05eeb16e30
19 changed files with 122 additions and 76 deletions

View File

@@ -1983,11 +1983,13 @@ class WP_Query {
$searchand = '';
$q['search_orderby_title'] = array();
foreach ( $q['search_terms'] as $term ) {
$term = like_escape( esc_sql( $term ) );
if ( $n )
$q['search_orderby_title'][] = "$wpdb->posts.post_title LIKE '%$term%'";
if ( $n ) {
$like = '%' . $wpdb->esc_like( $term ) . '%';
$q['search_orderby_title'][] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $like );
}
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
$like = $n . $wpdb->esc_like( $term ) . $n;
$search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title LIKE %s) OR ($wpdb->posts.post_content LIKE %s))", $like, $like );
$searchand = ' AND ';
}
@@ -2086,11 +2088,11 @@ class WP_Query {
if ( $q['search_terms_count'] > 1 ) {
$num_terms = count( $q['search_orderby_title'] );
$search_orderby_s = like_escape( esc_sql( $q['s'] ) );
$like = '%' . $wpdb->esc_like( $q['s'] ) . '%';
$search_orderby = '(CASE ';
// sentence match in 'post_title'
$search_orderby .= "WHEN $wpdb->posts.post_title LIKE '%{$search_orderby_s}%' THEN 1 ";
$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like );
// sanity limit, sort as sentence when more than 6 terms
// (few searches are longer than 6 terms and most titles are not)
@@ -2103,7 +2105,7 @@ class WP_Query {
}
// sentence match in 'post_content'
$search_orderby .= "WHEN $wpdb->posts.post_content LIKE '%{$search_orderby_s}%' THEN 4 ";
$search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like );
$search_orderby .= 'ELSE 5 END)';
} else {
// single word or sentence search