Skip to content

Commit 204db5b

Browse files
Copilotswissspidy
andcommitted
Add support for WordPress.org plugin/theme directory URLs
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 5e65b20 commit 204db5b

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

‎features/plugin-install.feature‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,55 @@ 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 STDOUT should contain:
286+
"""
287+
Installing Hello Dolly
288+
"""
289+
And STDOUT should contain:
290+
"""
291+
Plugin installed successfully.
292+
"""
293+
And the return code should be 0
294+
295+
When I run `wp plugin list --name=hello-dolly --field=status`
296+
Then STDOUT should be:
297+
"""
298+
inactive
299+
"""
300+
301+
Scenario: Install and activate plugin using WordPress.org directory URL
302+
Given a WP install
303+
304+
When I run `wp plugin install https://wordpress.org/plugins/akismet/ --activate`
305+
Then STDOUT should contain:
306+
"""
307+
Detected WordPress.org plugins directory URL, using slug: akismet
308+
"""
309+
And STDOUT should contain:
310+
"""
311+
Installing Akismet Anti-spam
312+
"""
313+
And STDOUT should contain:
314+
"""
315+
Plugin installed successfully.
316+
"""
317+
And STDOUT should contain:
318+
"""
319+
Activating 'akismet'...
320+
"""
321+
And the return code should be 0
322+
323+
When I run `wp plugin list --name=akismet --field=status`
324+
Then STDOUT should be:
325+
"""
326+
active
327+
"""

‎features/theme-install.feature‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,51 @@ 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 STDOUT should contain:
169+
"""
170+
Installing Twenty Twelve
171+
"""
172+
And STDOUT should contain:
173+
"""
174+
Theme installed successfully.
175+
"""
176+
And the return code should be 0
177+
178+
When I run `wp theme list --name=twentytwelve --field=status`
179+
Then STDOUT should be:
180+
"""
181+
inactive
182+
"""
183+
184+
Scenario: Install and activate theme using WordPress.org directory URL
185+
When I run `wp theme install https://wordpress.org/themes/twentyeleven/ --activate`
186+
Then STDOUT should contain:
187+
"""
188+
Detected WordPress.org themes directory URL, using slug: twentyeleven
189+
"""
190+
And STDOUT should contain:
191+
"""
192+
Installing Twenty Eleven
193+
"""
194+
And STDOUT should contain:
195+
"""
196+
Theme installed successfully.
197+
"""
198+
And STDOUT should contain:
199+
"""
200+
Activating 'twentyeleven'...
201+
"""
202+
And the return code should be 0
203+
204+
When I run `wp theme list --name=twentyeleven --field=status`
205+
Then STDOUT should be:
206+
"""
207+
active
208+
"""

‎src/WP_CLI/CommandWithUpgrade.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ 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+
if ( preg_match( '#^https?://wordpress\.org/(plugins|themes)/([^/]+)/?#', $slug, $matches ) ) {
219+
$slug = $matches[2];
220+
$is_remote = false;
221+
WP_CLI::log( sprintf( 'Detected WordPress.org %s directory URL, using slug: %s', $matches[1], $slug ) );
222+
}
215223
}
216224

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

0 commit comments

Comments
 (0)