Last active
December 25, 2015 22:29
-
-
Save PeterBooker/7050407 to your computer and use it in GitHub Desktop.
This gives an example of how to query the wordpress.org plugins API for data on all plugins.
This file contains 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 | |
/* | |
* Query the wordpress.org Plugins API | |
*/ | |
$query = array( | |
'action' => 'query_plugins', | |
'request' => serialize( | |
(object) array( | |
'page' => 1, | |
'per_page' => 100, | |
'search' => '', | |
'fields' => array( | |
'sections' => false, | |
'homepage' => true, | |
'tested' => true, | |
'last_updated' => true, | |
'description' => false, | |
'downloaded' => true, | |
'downloadlink' => true, | |
'tags' => true | |
) | |
) | |
) | |
); | |
// Setup arguments for POST request. | |
$args = array( | |
'method' => 'POST', | |
'timeout' => 10, | |
'redirection' => 5, | |
'httpversion' => '1.1', | |
'blocking' => true, | |
'headers' => array(), | |
'body' => $query, | |
'cookies' => array(), | |
'sslverify' => false, | |
); | |
$response = wp_remote_post( 'http://api.wordpress.org/plugins/info/1.0/', $args ); | |
if ( ! is_wp_error( $response ) ) { | |
echo '<pre>'; | |
print_r( unserialize( $response['body'] ) ); | |
echo '</pre>'; | |
} else { | |
echo '<pre>'; | |
print_r( $response ); | |
echo '</pre>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment