Last active
March 31, 2017 16:00
-
-
Save elliotcondon/e9dd5118e9eb32f0f0700f94c6349f78 to your computer and use it in GitHub Desktop.
Custom wordpress.org plugin download list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* get_my_plugin_downloads | |
* | |
* This function will return an array of plugin download information | |
* | |
* @type function | |
* @date 31/3/17 | |
* @since 5.5.10 | |
* | |
* @param $slug (string) | |
* @return (array) | |
*/ | |
function get_my_plugin_downloads( $slug = '' ) { | |
// vars | |
$plugin = array( | |
'version' => 0, | |
'download' => '', | |
'tags' => array() | |
); | |
$url = 'http://api.wordpress.org/plugins/info/1.0/' . $slug; | |
// connect | |
$request = wp_remote_post( $url ); | |
// success | |
if( !is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) { | |
// unserialize | |
$obj = @unserialize($request['body']); | |
// version | |
$plugin['version'] = $obj->version; | |
$plugin['url'] = 'https://downloads.wordpress.org/plugin/'.$slug.'.zip'; | |
// tags | |
preg_match_all('/<h4>(.+?)<\/h4>/', $obj->sections['changelog'], $matches); | |
// add tags | |
if( isset($matches[1]) ) { | |
foreach( $matches[1] as $tag ) { | |
$plugin['tags'][] = array( | |
'version' => $tag, | |
'url' => str_replace('.zip', '.'.$tag.'.zip', $plugin['url']) | |
); | |
} | |
} | |
} | |
// return | |
return $plugin; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$plugin = get_my_plugin_downloads('advanced-custom-fields'); | |
?> | |
<h2>Current Version</h2> | |
<ul> | |
<li><?php echo $plugin['version']; ?> - <a href="<?php echo $plugin['url']; ?>">download</a></li> | |
</ul> | |
<h2>Other Versions</h2> | |
<ul> | |
<?php foreach( $plugin['tags'] as $tag ): ?> | |
<li><?php echo $tag['version']; ?> - <a href="<?php echo $tag['url']; ?>">download</a></li> | |
<?php endforeach; ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@elliotcondon
Thanks for sharing the code.