like_escape() from nbachiyski. see #5684

git-svn-id: http://svn.automattic.com/wordpress/trunk@6680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-01-29 17:20:27 +00:00
parent 53c09007bb
commit 7d78a53a87
2 changed files with 12 additions and 2 deletions

View File

@ -268,8 +268,9 @@ function tag_rows( $page = 0, $pagesize = 20, $searchterms = '' ) {
$args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
if ( !empty( $searchterms ) )
$args['name__like'] = '%' . $searchterms;
if ( !empty( $searchterms ) ) {
$args['name__like'] = '%' . like_escape( $searchterms );
}
$tags = get_terms( 'post_tag', $args );

View File

@ -1164,6 +1164,15 @@ function attribute_escape($text) {
$safe_text = wp_specialchars($text, true);
return apply_filters('attribute_escape', $safe_text, $text);
}
/**
* Escapes text for SQL LIKE special characters % and _
*
* @param string text the text to be escaped
* @return string text, safe for inclusion in LIKE query
*/
function like_escape($text) {
return str_replace(array("%", "_"), array("\\%", "\\_"), $text);
}
function wp_make_link_relative( $link ) {
return preg_replace('|https?://[^/]+(/.*)|i', '$1', $link );