Make WordPress Core

Changeset 28892


Ignore:
Timestamp:
06/29/2014 10:04:05 AM (11 years ago)
Author:
johnbillion
Message:

Introduce a filter to control the minimum characters required for an AJAX term search. Fixes #13580. Props iamfriendly, brianlayman

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r28872 r28892  
    125125    }
    126126    $s = trim( $s );
    127     if ( strlen( $s ) < 2 )
    128         wp_die(); // require 2 chars for matching
     127
     128    /**
     129     * Filter the minimum number of characters required to fire a tag search via AJAX.
     130     *
     131     * @since 4.0.0
     132     *
     133     * @param int $characters The minimum number of characters required. Default 2.
     134     * @param object $tax The taxonomy object.
     135     * @param string $s The search term.
     136     */
     137    $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
     138
     139    /*
     140     * Require $term_search_min_chars chars for matching (default: 2)
     141     * ensure it's a non-negative, non-zero integer.
     142     */
     143    if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){
     144        wp_die();
     145    }
    129146
    130147    $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) );
Note: See TracChangeset for help on using the changeset viewer.