Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#55606 closed enhancement (fixed)

Add 'ajax_term_search_results' filter

Reported by: grandeljay's profile grandeljay Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords: has-screenshots has-patch needs-dev-note
Focuses: Cc:

Description

I want to create a plugin which suggests existing tags, if they are similar to existing tags. For this I want to hook into the term results, but it seems there is no way to. This filter should solve that.

https://github.com/WordPress/wordpress-develop/pull/2620

Attachments (2)

164680781-c672910a-969a-44e4-9bf6-898447b74ca1.png (10.3 KB) - added by grandeljay 3 years ago.
d91b8261cfa92283190f9ab82985336d.gif (639.1 KB) - added by audrasjb 2 years ago.
works fine with the above test snippet

Download all attachments as: .zip

Change History (18)

This ticket was mentioned in PR #2620 on WordPress/wordpress-develop by grandeljay.


3 years ago
#1

https://core.trac.wordpress.org/ticket/55606

I want to create a plugin which suggests existing tags, if they are similar to existing tags. For this I want to hook into the term results, but it seems there is no way to. This filter should solve that.

https://i0.wp.com/user-images.githubusercontent.com/45571053/164680781-c672910a-969a-44e4-9bf6-898447b74ca1.png

#2 @costdev
3 years ago

  • Keywords changes-requested needs-unit-tests added
  • Milestone changed from Awaiting Review to 6.1
  • Severity changed from trivial to normal
  • Version changed from trunk to 3.1

Hi @grandeljay, welcome to Trac and thanks for the PR!

I have added some thoughts in my review.

#3 @grandeljay
3 years ago

Thanks @costdev!

I've added my replies (not sure if you get notifications for those).

grandeljay commented on PR #2620:


3 years ago
#4

I think I figured out what went wrong with the unit test. It should work now 👍🏼

#5 @ironprogrammer
2 years ago

  • Keywords needs-testing needs-testing-info added; changes-requested needs-unit-tests removed

Referenced PR 2620 resolved dev reviewer feedback and includes unit tests. Tagged to move forward with testing.

#6 @audrasjb
2 years ago

PR tested using the following snippet:

function append_kokomo_tags( $results, $tax, $s ) {
	$kokomo = array( 'aruba', 'bermuda', 'key largo', 'montego' );

	$results = array_merge( $results, $kokomo );

	return $results;
}
add_filter( 'wp_after_tag_search', 'append_kokomo_tags', 10, 3 );

Works fine.

@audrasjb
2 years ago

works fine with the above test snippet

#7 @audrasjb
2 years ago

  • Keywords needs-testing needs-testing-info removed
  • Owner set to audrasjb
  • Status changed from new to accepted

#8 @audrasjb
2 years ago

  • Keywords needs-dev-note added

#9 @audrasjb
2 years ago

  • Keywords commit added

#10 follow-up: @SergeyBiryukov
2 years ago

  • Keywords changes-requested added; commit removed

For consistency with the existing term_search_min_chars filter just a few lines above in the same function, I think term_search_results would be a better name for this filter. (Starting them both with ajax_term_search_*, or ajax_tag_search_* to match the function name, would perhaps have been even better, but that ship has sailed.)

Generally, it appears that core uses the *_after_* wording for actions, not for filters.

#11 in reply to: ↑ 10 @SergeyBiryukov
2 years ago

Replying to SergeyBiryukov:

For consistency with the existing term_search_min_chars filter just a few lines above in the same function, I think term_search_results would be a better name for this filter.

Thinking about this some more, that seems a bit too generic :) Maybe ajax_term_search_results? Though it does not exactly align with the existing filter, I think it might be helpful to be more specific here.

#12 @costdev
2 years ago

@SergeyBiryukov Agreed! Using ajax_term_search_results makes sense here.

#13 @audrasjb
2 years ago

  • Keywords changes-requested removed

Agreed! I added one commit to the existing PR.

#14 @audrasjb
2 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 53781:

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.

#16 @SergeyBiryukov
2 years ago

  • Summary changed from Add wp_after_tag_search filter to Add 'ajax_term_search_results' filter

Renaming the ticket to match the name of the filter added in [53781].

Last edited 2 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.