Skip to content

Commit c82082b

Browse files
authored
Merge pull request #451 from wp-cli/fix-undefined
Handle case where paid plugin update is put into no_update array
2 parents d21a2f5 + 6e32ddc commit c82082b

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

features/plugin.feature

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,51 @@ Feature: Manage WordPress plugins
880880
Warning: example: This update requires WordPress version 100
881881
"""
882882

883+
@require-wp-4.0
884+
Scenario: Show plugin update as unavailable if it has a new version but no update package provided by author
885+
Given a WP install
886+
And a wp-content/plugins/example/example.php file:
887+
"""
888+
<?php
889+
/**
890+
* Plugin Name: Example Plugin
891+
* Version: 1.0.0
892+
* Requires at least: 3.7
893+
* Tested up to: 6.7
894+
"""
895+
And that HTTP requests to https://api.wordpress.org/plugins/update-check/1.1/ will respond with:
896+
"""
897+
HTTP/1.1 200 OK
898+
899+
{
900+
"plugins": [],
901+
"translations": [],
902+
"no_update": {
903+
"example/example.php": {
904+
"id": "w.org/plugins/example",
905+
"slug": "example",
906+
"plugin": "example/example.php",
907+
"new_version": "2.0.0",
908+
909+
"requires_plugins": [],
910+
"compatibility": []
911+
}
912+
}
913+
}
914+
"""
915+
916+
When I run `wp plugin list`
917+
Then STDOUT should be a table containing rows:
918+
| name | status | update | version | update_version | auto_update | requires | requires_php |
919+
| example | inactive | unavailable | 1.0.0 | 2.0.0 | off | | |
920+
921+
When I try `wp plugin update example`
922+
Then STDERR should contain:
923+
"""
924+
Warning: example: Update file not provided. Contact author for more details
925+
"""
926+
927+
883928
@require-wp-4.0
884929
Scenario: Show plugin update as unavailable if it doesn't meet PHP requirements
885930
Given a WP install

src/Plugin_Command.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,15 +864,22 @@ protected function get_item_list() {
864864
$items[ $file ]['requires_php'] = isset( $plugin_update_info->requires_php ) ? $plugin_update_info->requires_php : null;
865865
}
866866

867-
// If there is a plugin in no_update with a newer version than the local copy, it is because the plugins update api
868-
// has already filtered it because the local WordPress version is too low
867+
// If there is a plugin in no_update with a newer version than the local copy, it is either because:
868+
// A: the plugins update API has already filtered it because the local WordPress version is too low
869+
// B: It is possibly a paid plugin that has an update which the user does not qualify for
869870
if ( null !== $plugin_update_info && version_compare( $details['Version'], $plugin_update_info->new_version, '<' ) ) {
870871
$items[ $file ]['update'] = 'unavailable';
871872
$items[ $file ]['update_version'] = $plugin_update_info->new_version;
872873
$items[ $file ]['requires'] = isset( $plugin_update_info->requires ) ? $plugin_update_info->requires : null;
873874
$items[ $file ]['requires_php'] = isset( $plugin_update_info->requires_php ) ? $plugin_update_info->requires_php : null;
874875

875-
$reason = "This update requires WordPress version $plugin_update_info->requires, but the version installed is $wp_version.";
876+
if ( isset( $plugin_update_info->requires ) && version_compare( $wp_version, $requires, '>=' ) ) {
877+
$reason = "This update requires WordPress version $plugin_update_info->requires, but the version installed is $wp_version.";
878+
} elseif ( ! isset( $update_info['package'] ) ) {
879+
$reason = 'Update file not provided. Contact author for more details';
880+
} else {
881+
$reason = 'Update not available';
882+
}
876883

877884
$items[ $file ]['update_unavailable_reason'] = $reason;
878885

0 commit comments

Comments
 (0)