From 075be3e54bea1a3ad58ddd783d2d91f74f412728 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 29 Jun 2014 10:04:05 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/ajax-actions.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 754b869cc7..dff74ec683 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -124,8 +124,25 @@ function wp_ajax_ajax_tag_search() { $s = $s[count( $s ) - 1]; } $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 ) );