Introduce a filter to control the minimum characters required for an AJAX term search. Fixes #13580. Props iamfriendly, brianlayman
git-svn-id: https://develop.svn.wordpress.org/trunk@28892 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
416f6d01b2
commit
075be3e54b
@ -124,8 +124,25 @@ function wp_ajax_ajax_tag_search() {
|
|||||||
$s = $s[count( $s ) - 1];
|
$s = $s[count( $s ) - 1];
|
||||||
}
|
}
|
||||||
$s = trim( $s );
|
$s = trim( $s );
|
||||||
if ( strlen( $s ) < 2 )
|
|
||||||
wp_die(); // require 2 chars for matching
|
/**
|
||||||
|
* Filter the minimum number of characters required to fire a tag search via AJAX.
|
||||||
|
*
|
||||||
|
* @since 4.0.0
|
||||||
|
*
|
||||||
|
* @param int $characters The minimum number of characters required. Default 2.
|
||||||
|
* @param object $tax The taxonomy object.
|
||||||
|
* @param string $s The search term.
|
||||||
|
*/
|
||||||
|
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Require $term_search_min_chars chars for matching (default: 2)
|
||||||
|
* ensure it's a non-negative, non-zero integer.
|
||||||
|
*/
|
||||||
|
if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){
|
||||||
|
wp_die();
|
||||||
|
}
|
||||||
|
|
||||||
$results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) );
|
$results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user