Make WordPress Core


Ignore:
Timestamp:
07/26/2022 01:21:55 PM (4 years ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/TagSearch.php

    r53561 r53781  
    159159    }
    160160
     161    /**
     162     * Test the ajax_term_search_results filter
     163     *
     164     * @ticket 55606
     165     */
     166    public function test_ajax_term_search_results_filter() {
     167
     168        // Become an administrator.
     169        $this->_setRole( 'administrator' );
     170
     171        // Set up a default request.
     172        $_GET['tax'] = 'post_tag';
     173        $_GET['q']   = 'chat';
     174
     175        // Add the ajax_term_search_results filter.
     176        add_filter(
     177            'ajax_term_search_results',
     178            static function( $results, $tax, $s ) {
     179                return array( 'ajax_term_search_results was applied' );
     180            },
     181            10,
     182            3
     183        );
     184
     185        // Make the request.
     186        try {
     187            $this->_handleAjax( 'ajax-tag-search', $_GET['tax'], $_GET['q'] );
     188        } catch ( WPAjaxDieContinueException $e ) {
     189            unset( $e );
     190        }
     191
     192        // Ensure we found the right match.
     193        $this->assertSame( 'ajax_term_search_results was applied', $this->_last_response );
     194    }
    161195}
Note: See TracChangeset for help on using the changeset viewer.