Skip to content

Fix WordPress requirement check for unavailable plugin updates#531

Open
TowyTowy wants to merge 1 commit into
wp-cli:mainfrom
TowyTowy:fix/plugin-update-unavailable-wp-requires-reason
Open

Fix WordPress requirement check for unavailable plugin updates#531
TowyTowy wants to merge 1 commit into
wp-cli:mainfrom
TowyTowy:fix/plugin-update-unavailable-wp-requires-reason

Conversation

@TowyTowy

Copy link
Copy Markdown

Description

When a plugin update appears in the update API's no_update list with a newer version than the installed copy, Plugin_Command::get_item_list() computes the update_unavailable_reason that wp plugin update and wp plugin list surface. The WordPress-version branch had two problems:

  1. It compared the running WordPress version against $requires, but by that point $requires has been reassigned to the installed plugin's own "Requires at least" header (the display fallback a few lines above), not the update's required version ($plugin_update_info->requires).
  2. It used >= (requirement met) to gate the "requirement not met" message.

The net effect: the message "This update requires WordPress version X, but the version installed is Y" was shown whenever the site met the plugin's own minimum — almost always true — so updates that are unavailable for other reasons (for example paid plugins served via no_update) reported a nonsensical WordPress-version reason (Y ≥ X). Conversely, when a plugin's own header exceeded the running WordPress version, the genuine reason was suppressed.

This compares the running WordPress version against the update's own requires value using <, matching the behavior already implemented correctly for themes in ParseThemeNameInput::get_all_items().

Introduced in #440.

How to reproduce

Install a plugin, then have the update-check API return the plugin in no_update with a newer new_version and a requires value the site satisfies. wp plugin update <slug> warns "This update requires WordPress version …" even though the installed version meets that requirement.

Testing

Adds a Behat scenario in features/plugin.feature asserting the WordPress-requirement reason is not emitted when the site already meets the update's requires. PHPStan (level 9) and PHPCS pass. (No standalone PHPUnit exists for command logic; the repo covers this via Behat, which needs a live WP install.)


Disclosure: prepared with assistance from Claude (Anthropic); reviewed and verified before submission.

When an update is present in the update API's `no_update` list with a
newer version than the installed copy, `get_item_list()` derives the
`update_unavailable_reason` that `wp plugin update`/`wp plugin list`
surface. The WordPress-version branch compared the installed WordPress
version against `$requires`, which by that point holds the *installed*
plugin's own "Requires at least" header (line 972-974 fallback), and used
`>=` instead of `<`.

As a result the "This update requires WordPress version X" message was
emitted whenever the site met the plugin's own minimum (almost always
true) rather than when the site actually failed the update's WordPress
requirement, producing a nonsensical reason for updates that are
unavailable for other reasons (e.g. paid plugins), and hiding it when the
plugin's own header exceeded the running WordPress version.

Compare the running WordPress version against the update's own
`requires` value with `<`, matching the correct behavior already used for
themes in ParseThemeNameInput::get_all_items().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@TowyTowy
TowyTowy requested a review from a team as a code owner July 11, 2026 13:16
@github-actions

Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@github-actions github-actions Bot added bug command:plugin-update Related to 'plugin update' command scope:testing Related to testing labels Jul 11, 2026
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect “requires WordPress version …” unavailability messaging for plugin updates surfaced via the update API’s no_update list by comparing against the update’s own requires value (and using the correct comparison direction), aligning behavior with the existing theme handling.

Changes:

  • Correct WordPress version requirement check in Plugin_Command::get_item_list() to compare $wp_version against $plugin_update_info->requires using <.
  • Add a Behat scenario asserting the WordPress-requirement warning is not emitted when the site already meets the update’s requires.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Plugin_Command.php Fixes the WordPress-version gating logic for update_unavailable_reason when updates come from no_update.
features/plugin.feature Adds regression coverage ensuring the incorrect WordPress requirement warning is not shown when requirements are satisfied.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Plugin_Command.php
Comment on lines +1052 to 1055
if ( isset( $plugin_update_info->requires ) && version_compare( $wp_version, $plugin_update_info->requires, '<' ) ) {
$reason = "This update requires WordPress version $plugin_update_info->requires, but the version installed is $wp_version.";
} elseif ( ! isset( $plugin_update_info->package ) ) {
$reason = 'Update file not provided. Contact author for more details';
@swissspidy

Copy link
Copy Markdown
Member

cc @mrsdizzie since you worked on the original implementation here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:plugin-update Related to 'plugin update' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants