@@ -97,6 +97,9 @@ public function check_update( $_, $assoc_args ) {
9797 *
9898 * ## OPTIONS
9999 *
100+ * [<download-url>]
101+ * : Download directly from a provided URL instead of fetching the URL from the wordpress.org servers.
102+ *
100103 * [--path=<path>]
101104 * : Specify the path in which to install WordPress. Defaults to current
102105 * directory.
@@ -105,7 +108,7 @@ public function check_update( $_, $assoc_args ) {
105108 * : Select which language you want to download.
106109 *
107110 * [--version=<version>]
108- * : Select which version you want to download. Accepts a version number, 'latest' or 'nightly'
111+ * : Select which version you want to download. Accepts a version number, 'latest' or 'nightly'.
109112 *
110113 * [--skip-content]
111114 * : Download WP without the default themes and plugins.
@@ -153,7 +156,18 @@ public function download( $args, $assoc_args ) {
153156 $ locale = Utils \get_flag_value ( $ assoc_args , 'locale ' , 'en_US ' );
154157 $ skip_content = Utils \get_flag_value ( $ assoc_args , 'skip-content ' );
155158
156- if ( isset ( $ assoc_args ['version ' ] ) && 'latest ' !== $ assoc_args ['version ' ] ) {
159+ $ download_url = array_shift ( $ args );
160+ $ from_url = ! empty ( $ download_url );
161+
162+ if ( $ from_url ) {
163+ $ version = null ;
164+ if ( isset ( $ assoc_args ['version ' ] ) ) {
165+ WP_CLI ::error ( 'Version option is not available for URL downloads. ' );
166+ }
167+ if ( $ skip_content || 'en_US ' !== $ locale ) {
168+ WP_CLI ::error ( 'Skip content and locale options are not available for URL downloads. ' );
169+ }
170+ } elseif ( isset ( $ assoc_args ['version ' ] ) && 'latest ' !== $ assoc_args ['version ' ] ) {
157171 $ version = $ assoc_args ['version ' ];
158172 if ( in_array ( strtolower ( $ version ), [ 'trunk ' , 'nightly ' ], true ) ) {
159173 $ version = 'nightly ' ;
@@ -187,7 +201,11 @@ public function download( $args, $assoc_args ) {
187201 $ from_version = $ wp_details ['wp_version ' ];
188202 }
189203
190- WP_CLI ::log ( "Downloading WordPress {$ version } ( {$ locale })... " );
204+ if ( $ from_url ) {
205+ WP_CLI ::log ( "Downloading from {$ download_url } ... " );
206+ } else {
207+ WP_CLI ::log ( "Downloading WordPress {$ version } ( {$ locale })... " );
208+ }
191209
192210 $ path_parts = pathinfo ( $ download_url );
193211 $ extension = 'tar.gz ' ;
@@ -202,9 +220,13 @@ public function download( $args, $assoc_args ) {
202220 WP_CLI ::error ( 'Skip content is only available for ZIP files. ' );
203221 }
204222
205- $ cache = WP_CLI ::get_cache ();
206- $ cache_key = "core/wordpress- {$ version }- {$ locale }. {$ extension }" ;
207- $ cache_file = $ cache ->has ( $ cache_key );
223+ $ cache = WP_CLI ::get_cache ();
224+ if ( $ from_url ) {
225+ $ cache_file = null ;
226+ } else {
227+ $ cache_key = "core/wordpress- {$ version }- {$ locale }. {$ extension }" ;
228+ $ cache_file = $ cache ->has ( $ cache_key );
229+ }
208230
209231 $ bad_cache = false ;
210232 if ( $ cache_file ) {
@@ -246,16 +268,16 @@ function () use ( $temp ) {
246268
247269 if ( 'nightly ' !== $ version ) {
248270 $ md5_response = Utils \http_request ( 'GET ' , $ download_url . '.md5 ' );
249- if ( 20 !== (int ) substr ( $ md5_response ->status_code , 0 , 2 ) ) {
250- WP_CLI ::error ( "Couldn't access md5 hash for release (HTTP code {$ response ->status_code }). " );
251- }
252-
253- $ md5_file = md5_file ( $ temp );
271+ if ( $ md5_response ->status_code >= 200 && $ md5_response ->status_code < 300 ) {
272+ $ md5_file = md5_file ( $ temp );
254273
255- if ( $ md5_file === $ md5_response ->body ) {
256- WP_CLI ::log ( 'md5 hash verified: ' . $ md5_file );
274+ if ( $ md5_file === $ md5_response ->body ) {
275+ WP_CLI ::log ( 'md5 hash verified: ' . $ md5_file );
276+ } else {
277+ WP_CLI ::error ( "md5 hash for download ( {$ md5_file }) is different than the release hash ( {$ md5_response ->body }). " );
278+ }
257279 } else {
258- WP_CLI ::error ( "md5 hash for download ( {$ md5_file } ) is different than the release hash ( {$ md5_response ->body }). " );
280+ WP_CLI ::warning ( "Couldn't access md5 hash for release ( {$ download_url } .md5, HTTP code {$ md5_response ->status_code }). " );
259281 }
260282 } else {
261283 WP_CLI ::warning ( 'md5 hash checks are not available for nightly downloads. ' );
@@ -269,7 +291,9 @@ function () use ( $temp ) {
269291 WP_CLI ::error ( "Couldn't extract WordPress archive. {$ exception ->getMessage ()}" );
270292 }
271293
272- if ( 'nightly ' !== $ version ) {
294+ // Do not use the cache for nightly builds or for downloaded URLs
295+ // (the URL could be something like "latest.zip" or "nightly.zip").
296+ if ( ! $ from_url && 'nightly ' !== $ version ) {
273297 $ cache ->import ( $ cache_key , $ temp );
274298 }
275299 }
0 commit comments