Add filter hooks for AJAX suggest results#605
Conversation
Add source_id field to MslsFields for passing the source post/term ID in AJAX suggest requests.
Red phase: tests expect msls_meta_box_suggest_results and msls_post_tag_suggest_results filters that don't exist yet.
Add msls_meta_box_suggest_results filter and source_id hidden field to render_input(). The filter passes the results array and context (blog_id, post_type, search term, source_id).
Add msls_post_tag_suggest_results filter and source_id hidden field to term input templates.
Include the source post/term ID in the suggest AJAX request for filter context.
Account for the new msls_source_id hidden field in edit_input and add_input test expectations.
There was a problem hiding this comment.
Code Review
This pull request introduces a 'source_id' field to the post and term suggestion functionality within the Multisite Language Switcher. Key changes include the addition of a new constant in MslsFields, the inclusion of a hidden 'msls_source_id' input in meta boxes and tag edit screens, and an update to the AJAX logic in msls.js to transmit this ID. Furthermore, two new filters, 'msls_meta_box_suggest_results' and 'msls_post_tag_suggest_results', have been implemented to allow for the modification of suggestion results before they are returned. Corresponding unit tests have been updated to reflect these enhancements. I have no feedback to provide as there were no review comments to evaluate.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new source_id field to the suggestion logic for both posts and terms within the Multisite Language Switcher. Key changes include the addition of a FIELD_SOURCE_ID constant, the inclusion of hidden input fields in the meta box and post tag interfaces to track the source ID, and updates to the AJAX request in msls.js to transmit this value. Furthermore, new WordPress filters (msls_meta_box_suggest_results and msls_post_tag_suggest_results) have been implemented to allow for the modification of suggestion results before they are returned. Corresponding PHPUnit tests have been updated to verify these enhancements. I have no feedback to provide as there were no review comments to evaluate.
|
Verified locally with the following mu plugin: |
Summary
msls_meta_box_suggest_resultsandmsls_post_tag_suggest_resultsfilters on the final suggest results array, enabling add-on plugins to re-sort, relabel, insert spacers, or reorder translation candidatessource_id(the post/term being edited) through JS AJAX request and into the filter context, so consumers can implement heuristic matchingFIELD_SOURCE_IDconstant inMslsFieldswith hidden field in both post metabox and term input templatesCloses #604
Test plan
msls_meta_box_suggest_results, confirm modified results appear in autocomplete dropdown