Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update_url field to wp plugin list #176

Closed
1 task done
BrianHenryIE opened this issue Apr 27, 2023 · 2 comments
Closed
1 task done

Add update_url field to wp plugin list #176

BrianHenryIE opened this issue Apr 27, 2023 · 2 comments

Comments

@BrianHenryIE
Copy link
Member

BrianHenryIE commented Apr 27, 2023

Feature Request

Describe your use case and the problem you are facing

I would like to be able to list the download URLs for plugin updates. For premium plugins, where the licence key can only be used on one site, I need to get the authenticated download URL so I can download with cURL and test the plugin locally.

Currently this table can be generated:

$ wp plugin list --update=available --fields=name,status,update,version,update_version

+------------------+--------+-----------+---------+----------------+
| name             | status | update    | version | update_version |
+------------------+--------+-----------+---------+----------------+
| a-premium-plugin | active | available | 1.2.3   | 2.3.4          |
+------------------+--------+-----------+---------+----------------+

Describe the solution you'd like

$ wp plugin list --update=available --fields=name,status,update,version,update_version,update_url

+------------------+--------+-----------+---------+----------------+---------------------------------------------------------------+
| name             | status | update    | version | update_version | update_url                                                    |
+------------------+--------+-----------+---------+----------------+---------------------------------------------------------------+
| a-premium-plugin | active | available | 1.2.3   | 2.3.4          | https://pluginsite.com/a-premium-plugin.2.3.4.zip?auth=yes123 |
+------------------+--------+-----------+---------+----------------+---------------------------------------------------------------+

The gist to get the URLs is:

/** @var array<string, string> $plugin_update_urls The plugin update download links keyed by plugin basename. */
$plugin_update_urls = array();

/**
 * The plugin update data (which drives the yellow boxes on plugins.php).
 *
 * @see wp_update_plugins()
 * @see wp-includes/update.php
 *
 * @var stdClass{last_checked:string,response:array,translations:array,no_update:array,checked:array<string,string>} $plugin_updates
 */
$plugin_updates = get_site_transient('update_plugins');

/**
 * Get all valid plugin update URLs.
 *
 * @var string  $plugin_basename
 * @var stdClass{new_version:string, stable_version:string,name:string,slug:string,url:string,last_updated:string,homepage:string,package:string,download_link?:string,sections:stdClass{description:string,changelog?:string},banners:stdClass{high:string,low:string},icons:string} $values
 */
foreach ($plugin_updates->response as $plugin_basename => $values) {
    if ( filter_var($values->package, FILTER_VALIDATE_URL) ) {
        $plugin_update_urls[$plugin_basename] = $values->package;
    }
}

I'm imagining running something like this on my local computer:
wp plugin install $(wp plugin list --update=available --fields=update_url --ssh=production.com~/wp)

@danielbachhuber
Copy link
Member

I'm open to adding update_url as an optional field. Your proposed approach seems reasonable.

@BrianHenryIE
Copy link
Member Author

So, I finally checked out the extension repo today to take a look at this and it's already implemented!

wp plugin list --update=available --fields=name,version,update_version,update_package

update_package being the keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants