Skip to content

Instantly share code, notes, and snippets.

@BrianHenryIE
Created April 27, 2023 20:07
Show Gist options
  • Save BrianHenryIE/0ef2a8e91b25b25a2663dd70186b410e to your computer and use it in GitHub Desktop.
Save BrianHenryIE/0ef2a8e91b25b25a2663dd70186b410e to your computer and use it in GitHub Desktop.
Get the list of plugin update URLs on a WordPress site
<?php
/**
* Get the list of plugin update URLs for a site, so they can be downloaded and tested locally/on staging before installing on production.
*
* Often plugins' licence keys can only be installed on one site, production is obviously chosen, then the plugin update
* can only be downloaded on production.
*/
/** @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;
}
}
// Filter out plugins on the .org repo.
array_filter( $plugin_update_urls, function( string $url ): bool {
return 0 !== strpos($url,'https://downloads.wordpress.org');
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment