fix(checks): validate each Requires Plugins dependency individually#1391
fix(checks): validate each Requires Plugins dependency individually#1391faisalahammad wants to merge 2 commits into
Conversation
- Report a separate error per malformed slug in the Requires Plugins header, naming the offending slug, instead of one generic message for the whole comma-separated value - Add a warning per declared dependency that is not installed or not active in the environment the check runs in This gives plugin authors clear, per-dependency feedback when they declare more than one plugin dependency, instead of a single vague error covering the entire header. Fixes WordPress#1385
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for the contribution. I see reasonable. |
|
I think PR is following incorrect approach. Checking whether parent plugin is installed/active or not the responsibility of PCP or the actual check it was intended. We should check of that slug is active and published in the WordPress.org directory. |
|
Thanks for the feedback, this makes sense. I agree checking local install/active state is not the right job for a Pushed an update (689a1a1): the check now queries the WordPress.org plugin directory ( If the API is unreachable the check skips silently rather than risk a false positive, same convention as the existing WP-version check. |
Check no longer inspects local install/active state, per ernilambar's review feedback that this isn't the responsibility of a plugin_repo check. Each declared dependency slug is now looked up against the WordPress.org plugin directory API instead, warning only when the slug can't be found there (covers nonexistent and closed plugins). API calls are transient-cached and fail silently when unreachable. Refs WordPress#1391
Summary
Plugin Check currently validates the
Requires Pluginsheader as a single comma-separated blob, so a plugin declaring more than one dependency gets one generic "header is not valid" error with no indication of which slug is the problem, or whether the declared dependency actually exists in the WordPress.org plugin directory. This updatesPlugin_Header_Fields_Checkto validate each declared dependency individually and report its status on its own.Fixes #1385
Changes
includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php
Before:
After:
Each malformed slug is now reported as its own error, naming the slug. Each validly formatted slug is checked against the WordPress.org plugin directory (via
https://api.wordpress.org/plugins/info/1.0/{slug}.json, transient-cached for a day): a warning is added if the slug can't be found there (covers both nonexistent and closed/removed plugins, since the directory API returns anerrorkey for both). If the directory API can't be reached, the check skips silently rather than risk a false positive.Why: Plugin authors declaring multiple dependencies had no way to tell which one was wrong. ernilambar pointed out in review that checking local install/active state isn't this check's job — a
plugin_repocategory check should validate repo-readiness, i.e. whether the declared slug actually exists in the WordPress.org directory, since a parent plugin missing from the directory means the child plugin can't be published there either. The original approach (checkingis_plugin_inactive()against the local scan environment) has been replaced entirely with this directory-existence check.Testing
Test 1: Multiple invalid slugs are reported individually
Requires Plugins: Example Plugin, OtherPluginin a test plugin's header.Result: two separate errors, one naming "Example Plugin" and one naming "OtherPlugin", instead of a single generic message.
Test 2: Valid multi-dependency header passes format validation
Requires Plugins: woocommerce, contact-form-7.Result: no
plugin_header_invalid_requires_pluginserrors.Test 3: Dependency directory-existence warnings
Requires Plugins: plugin-check, hello-dolly, not-a-real-plugin.Result: warning naming
not-a-real-pluginas not found in the WordPress.org plugin directory; no warning forplugin-checkorhello-dolly(both published there).Updated PHPUnit tests in
tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php(transients are seeded directly in tests rather than mocking the HTTP call, matching the existing convention used forVersion_Utils/RequiresWPin the same file/class). Full suite (482 tests) passes, phpcs and phpstan clean.