mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
Taxonomy: Allow filtering Ajax term search results in quick edit.
This changeset introduces the `ajax_term_search_results` hook which can be used to filter the term search results returned by the AJAX term query. Props grandeljay, costdev, ironprogrammer, audrasjb, SergeyBiryukov. Fixes #55606. git-svn-id: https://develop.svn.wordpress.org/trunk@53781 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -162,6 +162,17 @@ function wp_ajax_ajax_tag_search() {
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the Ajax term search results.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param string[] $results Array of term names.
|
||||
* @param WP_Taxonomy $tax The taxonomy object.
|
||||
* @param string $s The search term.
|
||||
*/
|
||||
$results = apply_filters( 'ajax_term_search_results', $results, $tax, $s );
|
||||
|
||||
echo implode( "\n", $results );
|
||||
wp_die();
|
||||
}
|
||||
|
||||
@@ -158,4 +158,38 @@ class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
|
||||
$this->_handleAjax( 'ajax-tag-search' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ajax_term_search_results filter
|
||||
*
|
||||
* @ticket 55606
|
||||
*/
|
||||
public function test_ajax_term_search_results_filter() {
|
||||
|
||||
// Become an administrator.
|
||||
$this->_setRole( 'administrator' );
|
||||
|
||||
// Set up a default request.
|
||||
$_GET['tax'] = 'post_tag';
|
||||
$_GET['q'] = 'chat';
|
||||
|
||||
// Add the ajax_term_search_results filter.
|
||||
add_filter(
|
||||
'ajax_term_search_results',
|
||||
static function( $results, $tax, $s ) {
|
||||
return array( 'ajax_term_search_results was applied' );
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
|
||||
// Make the request.
|
||||
try {
|
||||
$this->_handleAjax( 'ajax-tag-search', $_GET['tax'], $_GET['q'] );
|
||||
} catch ( WPAjaxDieContinueException $e ) {
|
||||
unset( $e );
|
||||
}
|
||||
|
||||
// Ensure we found the right match.
|
||||
$this->assertSame( 'ajax_term_search_results was applied', $this->_last_response );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user