Skip to content

Fix url field in plugin search#474

Merged
swissspidy merged 4 commits intomainfrom
fix/470-docs
Nov 6, 2025
Merged

Fix url field in plugin search#474
swissspidy merged 4 commits intomainfrom
fix/470-docs

Conversation

@swissspidy
Copy link
Copy Markdown
Member

@swissspidy swissspidy commented Nov 6, 2025

Fixes #470

@swissspidy swissspidy requested a review from a team as a code owner November 6, 2025 13:17
@swissspidy swissspidy added scope:documentation Related to documentation command:plugin Related to 'plugin' command labels Nov 6, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/WP_CLI/CommandWithUpgrade.php 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mrsdizzie
Copy link
Copy Markdown
Member

mrsdizzie commented Nov 6, 2025

I think this is meant to be manually created based on the slug:

WP_CLI::error( __( 'API error. Try Again.' ) );
}
$items = $api->$plural;
// Add `url` for plugin or theme on wordpress.org.
foreach ( $items as $index => $item_object ) {
if ( $item_object instanceof \stdClass ) {
$item_object->url = "https://wordpress.org/{$plural}/{$item_object->slug}/";
}
}

Edit: I see the bug...when it does $items = $api->$plural it is actually taking the api response $api which is an object and turning it into an array of (of arrays) $items

this check will then never pass:
if ( $item_object instanceof \stdClass ) {
and url does not get added. So the but here is that these are assumed to be objects, but are actually arrays.

this fixes it:

diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php
index 798d8ca9..ff5fd214 100755
--- a/src/WP_CLI/CommandWithUpgrade.php
+++ b/src/WP_CLI/CommandWithUpgrade.php
@@ -854,8 +854,8 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {

        // Add `url` for plugin or theme on wordpress.org.
        foreach ( $items as $index => $item_object ) {
-           if ( $item_object instanceof \stdClass ) {
-               $item_object->url = "https://wordpress.org/{$plural}/{$item_object->slug}/";
+         if ( is_array( $item_object ) ) {
+             $items[ $index ]['url'] = "https://wordpress.org/{$plural}/{$item_object['slug']}/";
            }
isla@Mac ~/test $ wp plugin search --fields=name,slug,url acf
Success: Showing 10 of 991 plugins.
+---------------------------------------------------------------+------------------------------------+-----------------------------------------------------------------+
| name                                                          | slug                               | url                                                             |
+---------------------------------------------------------------+------------------------------------+-----------------------------------------------------------------+
| Advanced Custom Fields (ACF®)                                 | advanced-custom-fields             | https://wordpress.org/plugins/advanced-custom-fields/           |
| Yoast SEO – Advanced SEO with real-time guidance and bu | wordpress-seo                      | https://wordpress.org/plugins/wordpress-seo/                    |
| ilt-in AI                                                     |                                    |                                                                 |
| Table Field Add-on for ACF and SCF                            | advanced-custom-fields-table-field | https://wordpress.org/plugins/advanced-custom-fields-table-fiel |
|                                                               |                                    | d/                                                              |
| ACF Content Analysis for Yoast SEO                            | acf-content-analysis-for-yoast-seo | https://wordpress.org/plugins/acf-content-analysis-for-yoast-se |
|                                                               |                                    | o/                                                              |
| Dynamic Elementor ACF Repeater                                | dynamic-elementor-acf-repeater     | https://wordpress.org/plugins/dynamic-elementor-acf-repeater/   |
| Filter Everything — Product Filter & WordPress Filte | filter-everything                  | https://wordpress.org/plugins/filter-everything/                |
| r                                                             |                                    |                                                                 |
| ACF Field For CF7                                             | acf-field-for-contact-form-7       | https://wordpress.org/plugins/acf-field-for-contact-form-7/     |
| Advanced Custom Fields: Extended                              | acf-extended                       | https://wordpress.org/plugins/acf-extended/                     |
| ACF: Better Search                                            | acf-better-search                  | https://wordpress.org/plugins/acf-better-search/                |
| Members – Membership & User Role Editor Plugin      | members                            | https://wordpress.org/plugins/members/                          |
+---------------------------------------------------------------+------------------------------------+-----------------------------------------------------------------+

@swissspidy
Copy link
Copy Markdown
Member Author

Oooh that makes a lot of sense! 6dd2924 does this and it works like a charm. Thank you!

@swissspidy swissspidy changed the title Remove url field from plugin command docs Fix url field in plugin search Nov 6, 2025
@swissspidy swissspidy added command:plugin-search Related to 'plugin search' command and removed command:plugin Related to 'plugin' command labels Nov 6, 2025
@swissspidy
Copy link
Copy Markdown
Member Author

Turns out it's a stdClass on older WP version using the older API, but an array on newer versions 💡

@swissspidy swissspidy merged commit 2dd2f70 into main Nov 6, 2025
40 of 42 checks passed
@swissspidy swissspidy deleted the fix/470-docs branch November 6, 2025 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:plugin-search Related to 'plugin search' command scope:documentation Related to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documented url field cannot be use in wp plugin search command's --fields option

2 participants