Created
February 15, 2017 10:29
-
-
Save pixelbart/f7a092f4b85af05f923f496a07595339 to your computer and use it in GitHub Desktop.
Use wordpress.org API (plugins & themes) with PHP curl
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 | |
/** | |
* WordPress.org Plugin API | |
*/ | |
// Plugin Slug | |
$slug = 'simple-marketplace-affiliate'; | |
$args = (object) array( 'slug' => $slug ); | |
$fields = array( 'action' => 'plugin_information', 'timeout' => 15, 'request' => serialize( $args ) ); | |
$url = 'http://api.wordpress.org/plugins/info/1.0/'; | |
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } | |
rtrim($fields_string, '&'); | |
$ch = curl_init(); | |
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); | |
$result = curl_exec($ch); | |
$result = unserialize($result); | |
curl_close($ch); | |
// Output (object) | |
echo '<pre>' . print_r($result, true) . '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment