Skip to content

Commit ca7357b

Browse files
authored
Merge pull request #483 from wp-cli/copilot/fix-plugin-install-zip-error
2 parents 5516e81 + ad32ec0 commit ca7357b

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

features/plugin-install.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,35 @@ Feature: Install WordPress plugins
273273
"""
274274
Error: No plugins installed.
275275
"""
276+
277+
Scenario: Install plugin using WordPress.org directory URL
278+
Given a WP install
279+
280+
When I run `wp plugin install https://wordpress.org/plugins/hello-dolly/`
281+
Then STDOUT should contain:
282+
"""
283+
Detected WordPress.org plugins directory URL, using slug: hello-dolly
284+
"""
285+
And the return code should be 0
286+
287+
When I run `wp plugin list --name=hello-dolly --field=status`
288+
Then STDOUT should be:
289+
"""
290+
inactive
291+
"""
292+
293+
Scenario: Install and activate plugin using WordPress.org directory URL
294+
Given a WP install
295+
296+
When I run `wp plugin install https://wordpress.org/plugins/hello-dolly/ --activate`
297+
Then STDOUT should contain:
298+
"""
299+
Detected WordPress.org plugins directory URL, using slug: hello-dolly
300+
"""
301+
And the return code should be 0
302+
303+
When I run `wp plugin list --name=hello-dolly --field=status`
304+
Then STDOUT should be:
305+
"""
306+
active
307+
"""

features/theme-install.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,31 @@ Feature: Install WordPress themes
158158
"""
159159
Error: No themes installed.
160160
"""
161+
162+
Scenario: Install theme using WordPress.org directory URL
163+
When I run `wp theme install https://wordpress.org/themes/twentytwelve/`
164+
Then STDOUT should contain:
165+
"""
166+
Detected WordPress.org themes directory URL, using slug: twentytwelve
167+
"""
168+
And the return code should be 0
169+
170+
When I run `wp theme list --name=twentytwelve --field=status`
171+
Then STDOUT should be:
172+
"""
173+
inactive
174+
"""
175+
176+
Scenario: Install and activate theme using WordPress.org directory URL
177+
When I run `wp theme install https://wordpress.org/themes/twentyeleven/ --activate`
178+
Then STDOUT should contain:
179+
"""
180+
Detected WordPress.org themes directory URL, using slug: twentyeleven
181+
"""
182+
And the return code should be 0
183+
184+
When I run `wp theme list --name=twentyeleven --field=status`
185+
Then STDOUT should be:
186+
"""
187+
active
188+
"""

src/Plugin_Command.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ protected function filter_item_list( $items, $args ) {
10041004
* ## OPTIONS
10051005
*
10061006
* <plugin|zip|url>...
1007-
* : One or more plugins to install. Accepts a plugin slug, the path to a local zip file, or a URL to a remote zip file.
1007+
* : One or more plugins to install. Accepts a plugin slug, the path to a local zip file, a URL to a remote zip file, or a URL to a WordPress.org plugin directory.
10081008
*
10091009
* [--version=<version>]
10101010
* : If set, get that particular version from wordpress.org, instead of the
@@ -1083,6 +1083,16 @@ protected function filter_item_list( $items, $args ) {
10831083
* Removing the old version of the plugin...
10841084
* Plugin updated successfully
10851085
* Success: Installed 1 of 1 plugins.
1086+
*
1087+
* # Install from a WordPress.org plugin directory URL
1088+
* $ wp plugin install https://wordpress.org/plugins/akismet/
1089+
* Detected WordPress.org plugins directory URL, using slug: akismet
1090+
* Installing Akismet Anti-spam: Spam Protection (3.1.11)
1091+
* Downloading install package from https://downloads.wordpress.org/plugin/akismet.3.1.11.zip...
1092+
* Unpacking the package...
1093+
* Installing the plugin...
1094+
* Plugin installed successfully.
1095+
* Success: Installed 1 of 1 plugins.
10861096
*/
10871097
public function install( $args, $assoc_args ) {
10881098

src/Theme_Command.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ protected function filter_item_list( $items, $args ) {
497497
* ## OPTIONS
498498
*
499499
* <theme|zip|url>...
500-
* : One or more themes to install. Accepts a theme slug, the path to a local zip file, or a URL to a remote zip file.
500+
* : One or more themes to install. Accepts a theme slug, the path to a local zip file, a URL to a remote zip file, or a URL to a WordPress.org theme directory.
501501
*
502502
* [--version=<version>]
503503
* : If set, get that particular version from wordpress.org, instead of the
@@ -535,6 +535,16 @@ protected function filter_item_list( $items, $args ) {
535535
*
536536
* # Install from a remote zip file
537537
* $ wp theme install http://s3.amazonaws.com/bucketname/my-theme.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef
538+
*
539+
* # Install from a WordPress.org theme directory URL
540+
* $ wp theme install https://wordpress.org/themes/twentysixteen/
541+
* Detected WordPress.org themes directory URL, using slug: twentysixteen
542+
* Installing Twenty Sixteen (1.2)
543+
* Downloading install package from http://downloads.wordpress.org/theme/twentysixteen.1.2.zip...
544+
* Unpacking the package...
545+
* Installing the theme...
546+
* Theme installed successfully.
547+
* Success: Installed 1 of 1 themes.
538548
*/
539549
public function install( $args, $assoc_args ) {
540550
if ( count( $args ) > 1 && Utils\get_flag_value( $assoc_args, 'activate', false ) ) {

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ public function install( $args, $assoc_args ) {
212212

213213
WP_CLI::log( 'Latest release resolved to ' . $version['name'] );
214214
}
215+
216+
// Check if this is a WordPress.org plugin/theme directory URL.
217+
// If so, extract the slug and treat it as a repository installation.
218+
// Pattern matches: https://wordpress.org/plugins/plugin-slug/ or https://wordpress.org/themes/theme-slug/
219+
// Capture group 1: type (plugins|themes)
220+
// Capture group 2: slug (the plugin or theme slug name)
221+
if ( preg_match( '~^https?://wordpress\.org/(plugins|themes)/([^/]+)/?$~', $slug, $matches ) ) {
222+
$slug = $matches[2]; // Extract the slug.
223+
$is_remote = false;
224+
WP_CLI::log( sprintf( 'Detected WordPress.org %s directory URL, using slug: %s', $matches[1], $slug ) );
225+
}
215226
}
216227

217228
// Check if a URL to a remote or local zip has been specified.

0 commit comments

Comments
 (0)