Skip to content

Commit 2dd2f70

Browse files
authored
Merge pull request #474 from wp-cli/fix/470-docs
2 parents 67129ca + ffdaf58 commit 2dd2f70

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

features/plugin-search.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ Feature: Search WordPress.org plugins
1818
"""
1919
name,slug,active_installs
2020
"""
21+
22+
Scenario: Search for plugins with url field
23+
Given a WP install
24+
25+
When I run `wp plugin search gutenberg --fields=slug,url --format=csv`
26+
Then STDOUT should contain:
27+
"""
28+
gutenberg,https://wordpress.org/plugins/gutenberg/
29+
"""

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,11 @@ protected function _search( $args, $assoc_args ) {
853853
$items = $api->$plural;
854854

855855
// Add `url` for plugin or theme on wordpress.org.
856+
// In older WP versions these used to be objects.
856857
foreach ( $items as $index => $item_object ) {
857-
if ( $item_object instanceof \stdClass ) {
858+
if ( is_array( $item_object ) ) {
859+
$items[ $index ]['url'] = "https://wordpress.org/{$plural}/{$item_object['slug']}/";
860+
} elseif ( $item_object instanceof \stdClass ) {
858861
$item_object->url = "https://wordpress.org/{$plural}/{$item_object->slug}/";
859862
}
860863
}

0 commit comments

Comments
 (0)