@@ -97,6 +97,9 @@ public function check_update( $_, $assoc_args ) {
97
97
*
98
98
* ## OPTIONS
99
99
*
100
+ * [<download-url>]
101
+ * : Download directly from a provided URL instead of fetching the URL from the wordpress.org servers.
102
+ *
100
103
* [--path=<path>]
101
104
* : Specify the path in which to install WordPress. Defaults to current
102
105
* directory.
@@ -105,7 +108,7 @@ public function check_update( $_, $assoc_args ) {
105
108
* : Select which language you want to download.
106
109
*
107
110
* [--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'.
109
112
*
110
113
* [--skip-content]
111
114
* : Download WP without the default themes and plugins.
@@ -153,7 +156,18 @@ public function download( $args, $assoc_args ) {
153
156
$ locale = Utils \get_flag_value ( $ assoc_args , 'locale ' , 'en_US ' );
154
157
$ skip_content = Utils \get_flag_value ( $ assoc_args , 'skip-content ' );
155
158
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 ' ] ) {
157
171
$ version = $ assoc_args ['version ' ];
158
172
if ( in_array ( strtolower ( $ version ), [ 'trunk ' , 'nightly ' ], true ) ) {
159
173
$ version = 'nightly ' ;
@@ -187,7 +201,11 @@ public function download( $args, $assoc_args ) {
187
201
$ from_version = $ wp_details ['wp_version ' ];
188
202
}
189
203
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
+ }
191
209
192
210
$ path_parts = pathinfo ( $ download_url );
193
211
$ extension = 'tar.gz ' ;
@@ -202,9 +220,13 @@ public function download( $args, $assoc_args ) {
202
220
WP_CLI ::error ( 'Skip content is only available for ZIP files. ' );
203
221
}
204
222
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
+ }
208
230
209
231
$ bad_cache = false ;
210
232
if ( $ cache_file ) {
@@ -246,16 +268,16 @@ function () use ( $temp ) {
246
268
247
269
if ( 'nightly ' !== $ version ) {
248
270
$ 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 );
254
273
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
+ }
257
279
} 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 }). " );
259
281
}
260
282
} else {
261
283
WP_CLI ::warning ( 'md5 hash checks are not available for nightly downloads. ' );
@@ -269,7 +291,9 @@ function () use ( $temp ) {
269
291
WP_CLI ::error ( "Couldn't extract WordPress archive. {$ exception ->getMessage ()}" );
270
292
}
271
293
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 ) {
273
297
$ cache ->import ( $ cache_key , $ temp );
274
298
}
275
299
}
0 commit comments