Skip to content

Instantly share code, notes, and snippets.

@kristarella
Forked from amylaneio/gist:efec62dbbfb1b6fa89684b96faa10700
Last active September 7, 2017 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristarella/5b45ec8f05f8ea805eb1a38677898bce to your computer and use it in GitHub Desktop.
Save kristarella/5b45ec8f05f8ea805eb1a38677898bce to your computer and use it in GitHub Desktop.
<?php
function plugins( $search ) {
$num = 10;
$order = 'ASC';
$orderby = 'name';
$fields = 'URL,title';
$url = 'https://api.wordpress.org/plugins/info/1.1/?action=query_plugins&request[search]='.urlencode( $search );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_FAILONERROR, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_VERBOSE, true);
$body = curl_exec( $ch );
$err = curl_errno( $ch );
$data = json_decode( $body, true );
if( $data ) {
echo '<?xml version="1.0"?><items>';
while (list($key, $plugin) = each( $data['plugins'] ) ) {
echo '<item uid="'.$key.'" arg="https://wordpress.com/plugins/'.$plugin['slug'].'"><title>'.$plugin['name'].'</title>
<subtitle>ENTER to paste URL. SHIFT for Markdown link. CMD to open.</subtitle>
<mod key="shift" subtitle="Create Markdown Link" arg="['.$plugin['name'].' Plugin](https://wordpress.com/plugins/'.$plugin['slug'].'/)" />
<mod key="option" subtitle="WordPress.org version" arg="https://wordpress.org/plugins/'.$plugin['slug'].'/" />
</item>';
}
echo "</items>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment