Skip to content
38 changes: 37 additions & 1 deletion features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Feature: Update WordPress core
When I run `wp core update`
Then STDOUT should contain:
"""
WordPress is up to date
WordPress is up to date at version
"""
And STDOUT should not contain:
"""
Expand Down Expand Up @@ -419,3 +419,39 @@ Feature: Update WordPress core
"""
</div>
"""

@require-php-7.0 @require-wp-6.1
Scenario: Attempting to downgrade without --force shows helpful message
Given a WP install

When I run `wp core version`
Then save STDOUT as {WP_CURRENT_VERSION}

When I try `wp core update --version=6.0`
Then STDOUT should contain:
"""
WordPress is up to date at version
"""
And STDOUT should contain:
"""
is older than the current version
"""
And STDOUT should contain:
"""
Use --force to update anyway
"""
And STDOUT should not contain:
"""
Success:
"""
And the return code should be 0

When I run `wp core update --version=6.0 --force`
Then STDOUT should contain:
"""
Updating to version 6.0
"""
And STDOUT should contain:
"""
Success: WordPress updated successfully.
"""
8 changes: 7 additions & 1 deletion src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,14 @@ static function () {

WP_CLI::success( 'WordPress updated successfully.' );
}
// Check if user attempted to downgrade without --force
} elseif ( ! empty( Utils\get_flag_value( $assoc_args, 'version' ) ) && version_compare( Utils\get_flag_value( $assoc_args, 'version' ), $wp_version, '<' ) ) {
// Requested version is older than current (downgrade attempt)
WP_CLI::log( "WordPress is up to date at version {$wp_version}." );
WP_CLI::log( 'The version you requested (' . Utils\get_flag_value( $assoc_args, 'version' ) . ") is older than the current version ({$wp_version})." );
WP_CLI::log( 'Use --force to update anyway (e.g., to downgrade to version ' . Utils\get_flag_value( $assoc_args, 'version' ) . ').' );
} else {
WP_CLI::success( 'WordPress is up to date.' );
WP_CLI::success( "WordPress is up to date at version {$wp_version}." );
}
}

Expand Down