Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions features/plugin-search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ Feature: Search WordPress.org plugins
"""
name,slug,active_installs
"""

Scenario: Search for plugins with url field
Given a WP install

When I run `wp plugin search gutenberg --fields=slug,url --format=csv`
Then STDOUT should contain:
"""
gutenberg,https://wordpress.org/plugins/gutenberg/
"""
5 changes: 4 additions & 1 deletion src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,11 @@ protected function _search( $args, $assoc_args ) {
$items = $api->$plural;

// Add `url` for plugin or theme on wordpress.org.
// In older WP versions these used to be objects.
foreach ( $items as $index => $item_object ) {
if ( $item_object instanceof \stdClass ) {
if ( is_array( $item_object ) ) {
$items[ $index ]['url'] = "https://wordpress.org/{$plural}/{$item_object['slug']}/";
} elseif ( $item_object instanceof \stdClass ) {
$item_object->url = "https://wordpress.org/{$plural}/{$item_object->slug}/";
}
}
Expand Down
Loading