Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions features/core-download.feature
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,35 @@ Feature: Download WordPress
"""
/root-level-directory/
"""

Scenario: Core download without the wp-content dir
Given an empty directory
And an empty cache

When I run `wp core download --skip-content`
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
Then the wp-settings.php file should exist


Scenario: Core download without the wp-content dir should error for non US locale
Given an empty directory
And an empty cache

When I try `wp core download --skip-content --locale=nl_NL`
Then STDERR should contain:
"""
Skip content build is only available for the en_US locale.
"""


Scenario: Core download without the wp-content dir should error if a version is set
Given an empty directory
And an empty cache

When I try `wp core download --skip-content --version=4.7`
Then STDERR should contain:
"""
Skip content build is only available for the latest version.
"""


21 changes: 21 additions & 0 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function check_update( $_, $assoc_args ) {
* [--force]
* : Overwrites existing files, if present.
*
* [--skip-content]
* : Download the latest version of WP without the default themes and plugins (en_US locale only)
*
* ## EXAMPLES
*
* $ wp core download --locale=nl_NL
Expand Down Expand Up @@ -158,6 +161,24 @@ public function download( $args, $assoc_args ) {
$download_url = str_replace( '.zip', '.tar.gz', $offer['download'] );
}

if ( true === \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-content' ) && 'en_US' !== $locale ) {
WP_CLI::error( 'Skip content build is only available for the en_US locale.' );
}

if ( true === \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-content' ) && isset( $assoc_args['version'] ) ) {
WP_CLI::error( 'Skip content build is only available for the latest version.' );
}

if ( true === \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-content' ) ) {
$response = Requests::get( 'https://api.wordpress.org/core/version-check/1.7/', null, array( 'timeout' => 30 ) );
if ( 200 === $response->status_code && ( $body = json_decode( $response->body ) ) && is_object( $body ) && isset( $body->offers[0]->packages->no_content ) && is_array( $body->offers ) ) {
$download_url = $body->offers[0]->packages->no_content;
$version = $body->offers[0]->version;
} else {
WP_CLI::error( 'Skip content build is not available.' );
}
}

if ( 'nightly' === $version && 'en_US' !== $locale ) {
WP_CLI::error( 'Nightly builds are only available for the en_US locale.' );
}
Expand Down