mirror of
https://ghproxy.net/https://github.com/wp-cli/extension-command.git
synced 2025-10-04 01:34:31 +08:00
Handle case where paid plugin update is put into no_update array
To avoid warning: PHP Notice: Undefined property: stdClass::$requires in /usr/local/etc/wp-cli/packages/vendor/wp-cli/extension-command/src/Plugin_Command.php on line 875
This commit is contained in:
parent
d21a2f504a
commit
6e32ddcf4a
2 changed files with 55 additions and 3 deletions
|
@ -880,6 +880,51 @@ Feature: Manage WordPress plugins
|
|||
Warning: example: This update requires WordPress version 100
|
||||
"""
|
||||
|
||||
@require-wp-4.0
|
||||
Scenario: Show plugin update as unavailable if it has a new version but no update package provided by author
|
||||
Given a WP install
|
||||
And a wp-content/plugins/example/example.php file:
|
||||
"""
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Example Plugin
|
||||
* Version: 1.0.0
|
||||
* Requires at least: 3.7
|
||||
* Tested up to: 6.7
|
||||
"""
|
||||
And that HTTP requests to https://api.wordpress.org/plugins/update-check/1.1/ will respond with:
|
||||
"""
|
||||
HTTP/1.1 200 OK
|
||||
|
||||
{
|
||||
"plugins": [],
|
||||
"translations": [],
|
||||
"no_update": {
|
||||
"example/example.php": {
|
||||
"id": "w.org/plugins/example",
|
||||
"slug": "example",
|
||||
"plugin": "example/example.php",
|
||||
"new_version": "2.0.0",
|
||||
|
||||
"requires_plugins": [],
|
||||
"compatibility": []
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run `wp plugin list`
|
||||
Then STDOUT should be a table containing rows:
|
||||
| name | status | update | version | update_version | auto_update | requires | requires_php |
|
||||
| example | inactive | unavailable | 1.0.0 | 2.0.0 | off | | |
|
||||
|
||||
When I try `wp plugin update example`
|
||||
Then STDERR should contain:
|
||||
"""
|
||||
Warning: example: Update file not provided. Contact author for more details
|
||||
"""
|
||||
|
||||
|
||||
@require-wp-4.0
|
||||
Scenario: Show plugin update as unavailable if it doesn't meet PHP requirements
|
||||
Given a WP install
|
||||
|
|
|
@ -864,15 +864,22 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
|
|||
$items[ $file ]['requires_php'] = isset( $plugin_update_info->requires_php ) ? $plugin_update_info->requires_php : null;
|
||||
}
|
||||
|
||||
// If there is a plugin in no_update with a newer version than the local copy, it is because the plugins update api
|
||||
// has already filtered it because the local WordPress version is too low
|
||||
// If there is a plugin in no_update with a newer version than the local copy, it is either because:
|
||||
// A: the plugins update API has already filtered it because the local WordPress version is too low
|
||||
// B: It is possibly a paid plugin that has an update which the user does not qualify for
|
||||
if ( null !== $plugin_update_info && version_compare( $details['Version'], $plugin_update_info->new_version, '<' ) ) {
|
||||
$items[ $file ]['update'] = 'unavailable';
|
||||
$items[ $file ]['update_version'] = $plugin_update_info->new_version;
|
||||
$items[ $file ]['requires'] = isset( $plugin_update_info->requires ) ? $plugin_update_info->requires : null;
|
||||
$items[ $file ]['requires_php'] = isset( $plugin_update_info->requires_php ) ? $plugin_update_info->requires_php : null;
|
||||
|
||||
$reason = "This update requires WordPress version $plugin_update_info->requires, but the version installed is $wp_version.";
|
||||
if ( isset( $plugin_update_info->requires ) && version_compare( $wp_version, $requires, '>=' ) ) {
|
||||
$reason = "This update requires WordPress version $plugin_update_info->requires, but the version installed is $wp_version.";
|
||||
} elseif ( ! isset( $update_info['package'] ) ) {
|
||||
$reason = 'Update file not provided. Contact author for more details';
|
||||
} else {
|
||||
$reason = 'Update not available';
|
||||
}
|
||||
|
||||
$items[ $file ]['update_unavailable_reason'] = $reason;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue