Plugins: Match translated plugin data in the Installed Plugins search#12336
Plugins: Match translated plugin data in the Installed Plugins search#12336dhrupo wants to merge 3 commits into
Conversation
The Installed Plugins list table displays translated plugin names, descriptions, and authors, but the search filtered against the raw (untranslated) plugin headers only. As a result, searching by the displayed (translated) name returned no results, even though the Add Plugins screen already matches translated names. Pass the plugin file to WP_Plugins_List_Table::_search_callback() via ARRAY_FILTER_USE_BOTH and also match against the translated plugin data from _get_plugin_data_markup_translate(), while still matching the original headers so searches by the untranslated value keep working. Adds regression tests covering search by translated name, original name, and a non-matching term. Fixes #64188.
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
|
||
| foreach ( $plugin_data_sets as $plugin_data ) { | ||
| foreach ( $plugin_data as $value ) { | ||
| if ( is_string( $value ) && false !== stripos( strip_tags( $value ), $term ) ) { |
There was a problem hiding this comment.
i think this can be simplified by using str-contains()
WordPress comes with a polyfil since 5.9
There was a problem hiding this comment.
Good point, you're right — the false !== stripos() is clunky. I've gone ahead and switched it to str_contains() (lowercasing both sides so the search stays case-insensitive). 👍
There was a problem hiding this comment.
Done — switched it to str_contains() in a26c5cc. I lowercased both sides first so the search stays case-insensitive (otherwise typing akismet would stop matching Akismet), and added a couple of mixed-case test cases to lock that in. Reads much nicer than the false !== stripos() dance, thanks for the nudge 👍
|
And mind that you want a ticket on trac related to this PR, otherwise it won't be prioritized |
|
Thanks for the heads-up! There is a ticket already, #64188, linked at the top of the description. It's showing the PR and |
Replace the false !== stripos() idiom with str_contains() per review feedback. The search term and each value are lowercased first so the search stays case-insensitive, and tests are added to cover matching across different letter cases.
Fixes a WordPress.Arrays.MultipleStatementAlignment warning flagged by the test suite coding-standards scan.
Summary
Make the Installed Plugins search (
Plugins → Installed Plugins) match the translated plugin name, description, and author that are shown in the list — not only the original (untranslated) values from the plugin file headers.Trac ticket: https://core.trac.wordpress.org/ticket/64188
Problem
When WordPress runs in a non-English locale, the Installed Plugins list table displays translated plugin names (from the plugin's
.mofiles). However, the search box only matched against the raw, untranslated plugin headers. Searching for a plugin by the name shown in the list returned no results.This is also inconsistent with the Add Plugins screen, whose search already matches translated names.
In
WP_Plugins_List_Table::prepare_items()the search runs against the rawget_plugins()data:…while the data is only passed through
_get_plugin_data_markup_translate()for display afterwards:So the user sees translated names but searches against untranslated strings.
Solution
_search_callback()usingARRAY_FILTER_USE_BOTH._search_callback(), in addition to the original header values, also match against the translated plugin data returned by_get_plugin_data_markup_translate().The extra translation work only runs while a search is active.
Testing instructions
Reproduction via WordPress Playground (provided on the ticket):
https://playground.wordpress.net/?language=de_DE&url=%2Fwp-admin%2Fplugins.php%3Fs%3DnichtManual:
Settings → General.Plugins → Installed Plugins. The plugin shows its translated name.Automated:
New regression tests cover search by translated name, search by original (untranslated) name, and a non-matching term. The translated-name test fails on trunk and passes with this change.
Use of AI Tools
wordpress-developDocker environment (before/after), and verified against PHPUnit and PHPCS by me.