Created
November 2, 2011 08:23
-
-
Save ryan-frankel/1333167 to your computer and use it in GitHub Desktop.
Get Info from WP database
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 | |
Plugin URI: http://plugins.swampedpublishing.com/wp-super-faq | |
Description: A lightweight Wordpress Plugin that implements an FAQ page on your site using simple jQuery animation for a clean, usable interface. | |
Version: 0.1 | |
Author: rfrankel | |
Author URI: http://plugins.swampedpublishing.com/ | |
License: GPL2 | |
Copyright 2011 Ryan S. Frankel (email : [email protected]) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
?> | |
<?php | |
/* ***************************************************************************** | |
ADD A SHORTCODE TO DISPLAY PLUGINS | |
***************************************************************************** */ | |
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' => 5, | |
'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; | |
print_r($plugin); | |
?><h2>Done!</h2><?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment