Skip to content

Fix WordPress requirement check for unavailable plugin updates - #531

Open
TowyTowy wants to merge 2 commits 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 2 commits into
wp-cli:mainfrom
TowyTowy:fix/plugin-update-unavailable-wp-requires-reason

Conversation

@TowyTowy

@TowyTowy TowyTowy commented Jul 11, 2026

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.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected update availability messaging when a plugin update requires a newer WordPress version.
    • Prevented misleading WordPress requirement warnings when the installed WordPress version already meets the update’s requirements.
    • Continued displaying accurate update status and requirement details for unavailable updates.

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.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 725ea4d5-a7e5-48f3-bca4-35e95c4e1329

📥 Commits

Reviewing files that changed from the base of the PR and between 950603b and d786f5b.

📒 Files selected for processing (2)
  • features/plugin.feature
  • src/Plugin_Command.php

📝 Walkthrough

Walkthrough

The plugin command now correctly determines when an unavailable update requires a newer WordPress version. A feature scenario verifies that satisfied WordPress requirements do not produce that warning while requirement fields remain listed.

Changes

Plugin update requirement reporting

Layer / File(s) Summary
Requirement check and validation
src/Plugin_Command.php, features/plugin.feature
get_item_list() compares the installed WordPress version against the update’s requires value, with feature coverage for unavailable updates whose requirements are already satisfied.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: command:plugin-list

Suggested reviewers: swissspidy, schlessera

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix to the unavailable-plugin-update WordPress requirement check.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@swissspidy swissspidy added this to the 2.3.7 milestone Jul 29, 2026
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