Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include optional 'auto_updates' field in plugin and theme lists #350

Merged
merged 5 commits into from Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -384,6 +384,7 @@ These fields are optionally available:
* title
* description
* file
* auto_update

**EXAMPLES**

Expand Down Expand Up @@ -1064,6 +1065,7 @@ These fields are optionally available:
* update_id
* title
* description
* auto_update

**EXAMPLES**

Expand Down
14 changes: 14 additions & 0 deletions features/plugin.feature
Expand Up @@ -696,3 +696,17 @@ Feature: Manage WordPress plugins
Then STDOUT should be a table containing rows:
| name | title | description |
| test-mu | Test mu-plugin | Test mu-plugin description |

@require-wp-5.5
Scenario: Listing plugins should include name and auto_update
Given a WP install
When I run `wp plugin list --fields=name,auto_update`
Then STDOUT should be a table containing rows:
| name | auto_update |
| hello | off |

When I run `wp plugin auto-updates enable hello`
And I try `wp plugin list --fields=name,auto_update`
Then STDOUT should be a table containing rows:
| name | auto_update |
| hello | on |
14 changes: 14 additions & 0 deletions features/theme.feature
Expand Up @@ -685,3 +685,17 @@ Feature: Manage WordPress themes
Success:
"""
And the return code should be 0

@require-wp-5.5
Scenario: Listing themes should include auto_update
Given a WP install
When I run `wp theme list --fields=auto_update`
Then STDOUT should be a table containing rows:
| auto_update |
| off |

When I run `wp theme auto-updates enable --all`
And I try `wp theme list --fields=auto_update`
Then STDOUT should be a table containing rows:
| auto_update |
| on |
10 changes: 10 additions & 0 deletions src/Plugin_Command.php
Expand Up @@ -255,6 +255,7 @@ protected function get_all_items() {
'title' => $mu_title,
'description' => $mu_description,
'file' => $file,
'auto_update' => false,
);
}

Expand All @@ -272,6 +273,7 @@ protected function get_all_items() {
'update_package' => null,
'update_id' => '',
'file' => $name,
'auto_update' => false,
];
}

Expand Down Expand Up @@ -690,6 +692,12 @@ protected function get_item_list() {
$items = [];
$duplicate_names = [];

$auto_updates = get_site_option( Plugin_AutoUpdates_Command::SITE_OPTION );

if ( false === $auto_updates ) {
$auto_updates = [];
}

foreach ( $this->get_all_plugins() as $file => $details ) {
$all_update_info = $this->get_update_info();
$update_info = ( isset( $all_update_info->response[ $file ] ) && null !== $all_update_info->response[ $file ] ) ? (array) $all_update_info->response[ $file ] : null;
Expand All @@ -711,6 +719,7 @@ protected function get_item_list() {
'title' => $details['Name'],
'description' => wordwrap( $details['Description'] ),
'file' => $file,
'auto_update' => in_array( $file, $auto_updates, true ),
];

if ( null === $update_info ) {
Expand Down Expand Up @@ -1174,6 +1183,7 @@ public function delete( $args, $assoc_args = array() ) {
* * title
* * description
* * file
* * auto_update
*
* ## EXAMPLES
*
Expand Down
1 change: 1 addition & 0 deletions src/Theme_Command.php
Expand Up @@ -859,6 +859,7 @@ public function delete( $args, $assoc_args ) {
* * update_id
* * title
* * description
* * auto_update
*
* ## EXAMPLES
*
Expand Down
16 changes: 12 additions & 4 deletions src/WP_CLI/CommandWithUpgrade.php
Expand Up @@ -510,10 +510,18 @@ protected function _list( $_, $assoc_args ) {
}

foreach ( $item as $field => &$value ) {
if ( true === $value ) {
$value = 'available';
} elseif ( false === $value ) {
$value = 'none';
if ( 'update' === $field ) {
if ( true === $value ) {
$value = 'available';
} elseif ( false === $value ) {
$value = 'none';
}
} elseif ( 'auto_update' === $field ) {
if ( true === $value ) {
$value = 'on';
} elseif ( false === $value ) {
$value = 'off';
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/WP_CLI/ParseThemeNameInput.php
Expand Up @@ -3,6 +3,7 @@
namespace WP_CLI;

use WP_CLI;
use Theme_AutoUpdates_Command;

trait ParseThemeNameInput {

Expand Down Expand Up @@ -68,6 +69,12 @@ private function get_all_themes() {
}
}

$auto_updates = get_site_option( Theme_AutoUpdates_Command::SITE_OPTION );

if ( false === $auto_updates ) {
$auto_updates = [];
}

foreach ( wp_get_themes() as $key => $theme ) {
$file = $theme->get_stylesheet_directory();

Expand All @@ -84,6 +91,7 @@ private function get_all_themes() {
'title' => $theme->get( 'Name' ),
'description' => wordwrap( $theme->get( 'Description' ) ),
'author' => $theme->get( 'Author' ),
'auto_update' => in_array( $theme->get_stylesheet(), $auto_updates, true ),
];

// Compare version and update information in theme list.
Expand Down