Software Developer

Get Download URL For Plugin in WordPress Plugin Repository

This is how you can get the URL of the latest download of a plugin in the WordPress plugin repository. This will get the link URL to the ZIP file of the latest release.

It does not return the HTML link tag, but rather only the URL.

This code goes into your functions.

PHP

/**
 * Get the download link URL for the zip file of the latest version of a plugin on the WordPress repo.
 */
function isa_latest_plugin_tag_download_url( $plugin_slug ) {
	$tag = 'Stable tag';
	$trunk_readme = @file( 'https://plugins.svn.wordpress.org/' . $plugin_slug . '/trunk/readme.txt' );

	if ( is_array( $trunk_readme ) ) {

		foreach( $trunk_readme as $i => $line ) {

			if ( substr_count( $line, $tag . ': ' ) > 0 ) {
				$latest_version = trim( substr( $line, strpos( $line, $tag . ': ' ) + strlen( $tag ) + 2 ) );

				return 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.' . $latest_version . '.zip';

			}
		}
	}

	return NULL;
}

By

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]