Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Created February 15, 2017 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pixelbart/f7a092f4b85af05f923f496a07595339 to your computer and use it in GitHub Desktop.
Save pixelbart/f7a092f4b85af05f923f496a07595339 to your computer and use it in GitHub Desktop.
Use wordpress.org API (plugins & themes) with PHP curl
<?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