Created
November 2, 2011 08:24
-
-
Save ryan-frankel/1333172 to your computer and use it in GitHub Desktop.
Get Info from WP Plugin API
This file contains hidden or 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 | |
/* | |
Plugin Name: WordPress API | |
clean, usable interface. | |
Version: 0.1 | |
?> | |
<?php | |
/* ***************************************************************************** | |
CREATE TABLE ON ACTIVATION | |
***************************************************************************** */ | |
register_activation_hook( __FILE__, 'wordpress_api_activate' ); | |
function wordpress_api_activate() { | |
// Create the table in the database | |
global $wpdb; | |
$table_name = $wpdb->prefix . "plugin_table"; | |
$sql = "CREATE TABLE " . $table_name . " ( | |
id INTEGER NOT NULL AUTO_INCREMENT, | |
name TEXT NOT NULL, | |
slug TEXT NOT NULL, | |
version TEXT NOT NULL, | |
author TEXT NOT NULL, | |
author_link TEXT NOT NULL, | |
contributors TEXT NOT NULL, | |
requires TEXT NOT NULL, | |
tested TEXT NOT NULL, | |
rating TEXT NOT NULL, | |
num_ratings TEXT NOT NULL, | |
downloaded TEXT NOT NULL, | |
last_updated TEXT NOT NULL, | |
homepage TEXT NOT NULL, | |
description TEXT NOT NULL, | |
short_description TEXT NOT NULL, | |
download_link TEXT NOT NULL, | |
tags TEXT NOT NULL, | |
UNIQUE KEY id (id) | |
);"; | |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
dbDelta($sql); | |
} | |
/* ***************************************************************************** | |
ADD A SHORTCODE TO DISPLAY PLUGINS | |
***************************************************************************** */ | |
// [wordpress_api] | |
add_shortcode( 'wordpress_api', 'wordpress_api_shortcode' ); | |
function wordpress_api_shortcode( $atts ) { | |
extract( shortcode_atts( array( | |
), $atts ) ); | |
// WordPress db | |
global $wpdb; | |
$table_name = $wpdb->prefix . "plugin_table"; | |
$current_page = 1; | |
$number_of_pages = 1; | |
?><h2>Info: http://dd32.id.au/projects/wordpressorg-plugin-information-api-docs/</h2><?php | |
while ( $current_page <= $number_of_pages ) : | |
$payload = array( | |
'action' => 'query_plugins', | |
'request' => serialize( | |
(object)array( | |
'search' => '', | |
'page' => (int)$current_page, | |
'per_page' => 100, | |
'fields' => array( | |
'downloaded' => true, | |
'downloadlink' => true, | |
'last_updated' => true, | |
'homepage' => true, | |
'tags' => true | |
), | |
) | |
) | |
); | |
$body = wp_remote_post( 'http://api.wordpress.org/plugins/info/1.0/', array( 'body' => $payload) ); | |
if ( !is_wp_error($body) ) { | |
$data = unserialize($body['body']); | |
$number_of_pages = $data->info['pages']; | |
/* $number_of_pages = 1; */ | |
$current_page = $current_page + 1; | |
foreach ($data->plugins as $plugin) { | |
$plugin_data = array( | |
'name' => $plugin->name, | |
'slug' => $plugin->slug, | |
'version' => $plugin->version, | |
'author' => $plugin->author, | |
'author_link' => $plugin->author_profile, //!!!!!!!! DEBUG | |
'contributors' => serialize($plugin->contributors), | |
'requires' => $plugin->requires, | |
'tested' => $plugin->tested, | |
'rating' => $plugin->rating, | |
'num_ratings' => $plugin->num_ratings, | |
'downloaded' => $plugin->downloaded, | |
'last_updated' => $plugin->last_updated, | |
'homepage' => $plugin->homepage, | |
'description' => $plugin->description, | |
'short_description' => $plugin->short_description, | |
'download_link' => $plugin->download_link, | |
'tags' => serialize($plugin->tags), | |
); | |
$wpdb->insert($table_name, $plugin_data); | |
} | |
} | |
endwhile; | |
?><h2>Done!</h2><?php | |
} | |
?>1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment