Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created May 29, 2012 23:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepmal/2831344 to your computer and use it in GitHub Desktop.
Save trepmal/2831344 to your computer and use it in GitHub Desktop.
Stand-alone WordPress.org plugin api access
<?php
// Stand-alone WordPress.org plugin api access
$url = 'http://api.wordpress.org/plugins/info/1.0/';
$fields = array(
'action' => 'query_plugins',
'request' => serialize( (object) array(
'author' => 'trepmal',
//'search' => 'howdy',
// 'page' => 1,
// 'per_page' => 20
) )
);
//url-ify the data for the POST
$fields_string = array();
foreach( $fields as $key => $value) {
$fields_string[] .= "{$key}={$value}";
}
$fields_string = implode( '&', $fields_string );
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, count( $fields ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields_string );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
$result = unserialize( $result );
//die( '<pre>'. print_r($result, true) .'</pre>' );
echo '<ul>';
foreach ( $result->plugins as $r ){
echo '<li>'. $r->name .'</li>';
}
echo '</ul>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment