Ticket #38922: 38922.8.diff
File 38922.8.diff, 5.4 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index 8ced5d335a..8861e154f0 100644
function wp_ajax_fetch_list() { 99 99 wp_die( 0 ); 100 100 } 101 101 102 /**103 * Ajax handler for tag search.104 *105 * @since 3.1.0106 */107 function wp_ajax_ajax_tag_search() {108 if ( ! isset( $_GET['tax'] ) ) {109 wp_die( 0 );110 }111 112 $taxonomy = sanitize_key( $_GET['tax'] );113 $tax = get_taxonomy( $taxonomy );114 if ( ! $tax ) {115 wp_die( 0 );116 }117 118 if ( ! current_user_can( $tax->cap->assign_terms ) ) {119 wp_die( -1 );120 }121 122 $s = wp_unslash( $_GET['q'] );123 124 $comma = _x( ',', 'tag delimiter' );125 if ( ',' !== $comma ) {126 $s = str_replace( $comma, ',', $s );127 }128 if ( false !== strpos( $s, ',' ) ) {129 $s = explode( ',', $s );130 $s = $s[ count( $s ) - 1 ];131 }132 $s = trim( $s );133 134 /**135 * Filters the minimum number of characters required to fire a tag search via Ajax.136 *137 * @since 4.0.0138 *139 * @param int $characters The minimum number of characters required. Default 2.140 * @param WP_Taxonomy $tax The taxonomy object.141 * @param string $s The search term.142 */143 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );144 145 /*146 * Require $term_search_min_chars chars for matching (default: 2)147 * ensure it's a non-negative, non-zero integer.148 */149 if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ) {150 wp_die();151 }152 153 $results = get_terms(154 $taxonomy, array(155 'name__like' => $s,156 'fields' => 'names',157 'hide_empty' => false,158 )159 );160 161 echo join( $results, "\n" );162 wp_die();163 }164 165 102 /** 166 103 * Ajax handler for compression testing. 167 104 * -
src/wp-admin/includes/deprecated.php
diff --git src/wp-admin/includes/deprecated.php src/wp-admin/includes/deprecated.php index e65fe5a79c..f6e249ca5e 100644
function options_permalink_add_js() { 1514 1514 </script> 1515 1515 <?php 1516 1516 } 1517 1518 /** 1519 * Ajax handler for tag search. 1520 * 1521 * @since 3.1.0 1522 * @deprecated 4.9.0 Use the REST API tags endpoint instead. 1523 */ 1524 function wp_ajax_ajax_tag_search() { 1525 _deprecated_function( __FUNCTION__, '4.8', '/wp-json/wp/v2/tags' ); 1526 1527 if ( ! isset( $_GET['tax'] ) ) { 1528 wp_die( 0 ); 1529 } 1530 1531 $taxonomy = sanitize_key( $_GET['tax'] ); 1532 $tax = get_taxonomy( $taxonomy ); 1533 if ( ! $tax ) { 1534 wp_die( 0 ); 1535 } 1536 1537 if ( ! current_user_can( $tax->cap->assign_terms ) ) { 1538 wp_die( -1 ); 1539 } 1540 1541 $s = wp_unslash( $_GET['q'] ); 1542 1543 $comma = _x( ',', 'tag delimiter' ); 1544 if ( ',' !== $comma ) { 1545 $s = str_replace( $comma, ',', $s ); 1546 } 1547 if ( false !== strpos( $s, ',' ) ) { 1548 $s = explode( ',', $s ); 1549 $s = $s[ count( $s ) - 1 ]; 1550 } 1551 $s = trim( $s ); 1552 1553 /** This filter is documented in wp-includes/script-loader.php */ 1554 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s ); 1555 1556 /* 1557 * Require $term_search_min_chars chars for matching (default: 2) 1558 * ensure it's a non-negative, non-zero integer. 1559 */ 1560 if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ) { 1561 wp_die(); 1562 } 1563 1564 $results = get_terms( 1565 $taxonomy, array( 1566 'name__like' => $s, 1567 'fields' => 'names', 1568 'hide_empty' => false, 1569 ) 1570 ); 1571 1572 echo join( $results, "\n" ); 1573 wp_die(); 1574 } -
src/wp-admin/js/tags-suggest.js
diff --git src/wp-admin/js/tags-suggest.js src/wp-admin/js/tags-suggest.js index 6465cc9959..0505988302 100644
53 53 54 54 term = getLast( request.term ); 55 55 56 $.get( window. ajaxurl, {57 action: 'ajax-tag-search',58 tax : taxonomy,59 q: term56 $.get( window.tagsSuggestL10n.restURL, { 57 _fields: [ 'id', 'name' ], 58 taxonomy: taxonomy, 59 search: term 60 60 } ).always( function() { 61 61 $element.removeClass( 'ui-autocomplete-loading' ); // UI fails to remove this sometimes? 62 62 } ).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 } 63 cache = data; 64 response( data ); 83 65 } ); 84 66 85 67 last = request.term; … … 118 100 close: function() { 119 101 $element.attr( 'aria-expanded', 'false' ); 120 102 }, 121 minLength: 2,103 minLength: window.tagsSuggestL10n.minChars, 122 104 position: { 123 105 my: 'left top+2', 124 106 at: 'left bottom', -
src/wp-includes/script-loader.php
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php index e0b63f44d3..98a5a0d1cc 100644
function wp_default_scripts( &$scripts ) { 726 726 'termSelected' => __( 'Term selected.' ), 727 727 'termAdded' => __( 'Term added.' ), 728 728 'termRemoved' => __( 'Term removed.' ), 729 'restURL' => rest_url( '/wp/v2/tags' ), 730 731 /** 732 * Filters the minimum number of characters required to fire a tag search via Ajax. 733 * 734 * Previous to 4.8.0, this filter passed taxonomy and search context parameters. 735 * @since 4.0.0 736 * 737 * @param int $characters The minimum number of characters required. Default 2. 738 */ 739 'minChars' => (int) apply_filters( 'term_search_min_chars', 2 ), 729 740 ) 730 741 ); 731 742