Make WordPress Core

Changeset 53781


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.

Location:
trunk
Files:
2 edited

Legend:

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

    r53747 r53781  
    162162                )
    163163        );
     164
     165        /**
     166         * Filters the Ajax term search results.
     167         *
     168         * @since 6.1.0
     169         *
     170         * @param string[]    $results Array of term names.
     171         * @param WP_Taxonomy $tax     The taxonomy object.
     172         * @param string      $s       The search term.
     173         */
     174        $results = apply_filters( 'ajax_term_search_results', $results, $tax, $s );
    164175
    165176        echo implode( "\n", $results );
  • 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.