Ticket #38922: 38922.4.diff
File 38922.4.diff, 5.4 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
99 99 } 100 100 101 101 /** 102 * Ajax handler for tag search.103 *104 * @since 3.1.0105 */106 function wp_ajax_ajax_tag_search() {107 if ( ! isset( $_GET['tax'] ) ) {108 wp_die( 0 );109 }110 111 $taxonomy = sanitize_key( $_GET['tax'] );112 $tax = get_taxonomy( $taxonomy );113 if ( ! $tax ) {114 wp_die( 0 );115 }116 117 if ( ! current_user_can( $tax->cap->assign_terms ) ) {118 wp_die( -1 );119 }120 121 $s = wp_unslash( $_GET['q'] );122 123 $comma = _x( ',', 'tag delimiter' );124 if ( ',' !== $comma )125 $s = str_replace( $comma, ',', $s );126 if ( false !== strpos( $s, ',' ) ) {127 $s = explode( ',', $s );128 $s = $s[count( $s ) - 1];129 }130 $s = trim( $s );131 132 /**133 * Filters the minimum number of characters required to fire a tag search via Ajax.134 *135 * @since 4.0.0136 *137 * @param int $characters The minimum number of characters required. Default 2.138 * @param WP_Taxonomy $tax The taxonomy object.139 * @param string $s The search term.140 */141 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );142 143 /*144 * Require $term_search_min_chars chars for matching (default: 2)145 * ensure it's a non-negative, non-zero integer.146 */147 if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){148 wp_die();149 }150 151 $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) );152 153 echo join( $results, "\n" );154 wp_die();155 }156 157 /**158 102 * Ajax handler for compression testing. 159 103 * 160 104 * @since 3.1.0 -
src/wp-admin/includes/deprecated.php
1396 1396 echo ' autocomplete="off"'; 1397 1397 } 1398 1398 } 1399 1400 /** 1401 * Ajax handler for tag search. 1402 * 1403 * @deprecated 4.8.0 Use the REST API tags endpoint instead. 1404 * 1405 * @since 3.1.0 1406 */ 1407 function wp_ajax_ajax_tag_search() { 1408 _deprecated_function( __FUNCTION__, '4.8', '/wp-json/wp/v2/tags' ); 1409 1410 if ( ! isset( $_GET['tax'] ) ) { 1411 wp_die( 0 ); 1412 } 1413 1414 $taxonomy = sanitize_key( $_GET['tax'] ); 1415 $tax = get_taxonomy( $taxonomy ); 1416 if ( ! $tax ) { 1417 wp_die( 0 ); 1418 } 1419 1420 if ( ! current_user_can( $tax->cap->assign_terms ) ) { 1421 wp_die( -1 ); 1422 } 1423 1424 $s = wp_unslash( $_GET['q'] ); 1425 1426 $comma = _x( ',', 'tag delimiter' ); 1427 if ( ',' !== $comma ) 1428 $s = str_replace( $comma, ',', $s ); 1429 if ( false !== strpos( $s, ',' ) ) { 1430 $s = explode( ',', $s ); 1431 $s = $s[count( $s ) - 1]; 1432 } 1433 $s = trim( $s ); 1434 1435 /** This filter is documented in wp-includes/script-loader.php */ 1436 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s ); 1437 1438 /* 1439 * Require $term_search_min_chars chars for matching (default: 2) 1440 * ensure it's a non-negative, non-zero integer. 1441 */ 1442 if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){ 1443 wp_die(); 1444 } 1445 1446 $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) ); 1447 1448 echo join( $results, "\n" ); 1449 wp_die(); 1450 } -
src/wp-admin/js/tags-suggest.js
53 53 54 54 term = getLast( request.term ); 55 55 56 $.get( window.ajaxurl, { 57 action: 'ajax-tag-search', 58 tax: taxonomy, 59 q: term 56 $.get( window.tagsSuggestL10n.restURL, { 57 taxonomy: taxonomy, 58 search: term 60 59 } ).always( function() { 61 60 $element.removeClass( 'ui-autocomplete-loading' ); // UI fails to remove this sometimes? 62 61 } ).done( function( data ) { 63 var tagName; 64 var tags = []; 65 66 if ( data ) { 67 data = data.split( '\n' ); 68 69 for ( tagName in data ) { 70 var id = ++tempID; 71 72 tags.push({ 73 id: id, 74 name: data[tagName] 75 }); 76 } 77 78 cache = tags; 79 response( tags ); 80 } else { 81 response( tags ); 82 } 62 cache = data; 63 response( data ); 83 64 } ); 84 65 85 66 last = request.term; … … 118 99 close: function() { 119 100 $element.attr( 'aria-expanded', 'false' ); 120 101 }, 121 minLength: 2,102 minLength: window.tagsSuggestL10n.minChars, 122 103 position: { 123 104 my: 'left top+2', 124 105 at: 'left bottom', -
src/wp-includes/script-loader.php
547 547 'termSelected' => __( 'Term selected.' ), 548 548 'termAdded' => __( 'Term added.' ), 549 549 'termRemoved' => __( 'Term removed.' ), 550 'restURL' => rest_url( '/wp/v2/tags' ), 551 552 /** 553 * Filters the minimum number of characters required to fire a tag search via Ajax. 554 * 555 * @since 4.0.0 556 * 557 * @param int $characters The minimum number of characters required. Default 2. 558 */ 559 'minChars' => (int) apply_filters( 'term_search_min_chars', 2 ), 550 560 ) ); 551 561 552 562 $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y' ), false, 1 );