Created
April 30, 2014 03:35
-
-
Save cgspicer/06da7c5bdc7fdd4bc514 to your computer and use it in GitHub Desktop.
Fishpig Wordpress integration extension patch of WP-API
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 | |
/** | |
* JSON API support for WordPress | |
* | |
* @package WordPress | |
*/ | |
/** | |
* Whether this is a XMLRPC Request | |
* | |
* @var bool | |
* @todo Remove me in favour of JSON_REQUEST | |
*/ | |
define('XMLRPC_REQUEST', true); | |
/** | |
* Whether this is a JSON Request | |
* | |
* @var bool | |
*/ | |
define('JSON_REQUEST', true); | |
/** Include the bootstrap for setting up WordPress environment */ | |
include('./wp-load.php'); | |
include_once(ABSPATH . 'wp-admin/includes/admin.php'); | |
// do not know why this is not working... but it's throwing an error, will look into it later-- possibly already defined | |
//include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); | |
include_once(ABSPATH . WPINC . '/class-wp-json-datetime.php'); | |
include_once(ABSPATH . WPINC . '/class-wp-json-server.php'); | |
// Allow for a plugin to insert a different class to handle requests. | |
$wp_json_server_class = apply_filters('wp_json_server_class', 'WP_JSON_Server'); | |
$wp_json_server = new $wp_json_server_class; | |
// stripped from the plugin.php initialization, this sets up the routes and support classes | |
global $wp_json_posts, $wp_json_pages, $wp_json_media, $wp_json_taxonomies; | |
// Posts | |
$wp_json_posts = new WP_JSON_Posts($wp_json_server); | |
add_filter( 'json_endpoints', array( $wp_json_posts, 'register_routes' ), 0 ); | |
// Pages | |
$wp_json_pages = new WP_JSON_Pages($wp_json_server); | |
$wp_json_pages->register_filters(); | |
// Media | |
$wp_json_media = new WP_JSON_Media($wp_json_server); | |
add_filter( 'json_endpoints', array( $wp_json_media, 'register_routes' ), 1 ); | |
add_filter( 'json_prepare_post', array( $wp_json_media, 'add_thumbnail_data' ), 10, 3 ); | |
add_filter( 'json_pre_insert_post', array( $wp_json_media, 'preinsert_check' ), 10, 3 ); | |
add_filter( 'json_insert_post', array( $wp_json_media, 'attach_thumbnail' ), 10, 3 ); | |
add_filter( 'json_post_type_data', array( $wp_json_media, 'type_archive_link' ), 10, 2 ); | |
// Posts | |
$wp_json_taxonomies = new WP_JSON_Taxonomies($server); | |
add_filter( 'json_endpoints', array( $wp_json_taxonomies, 'register_routes' ), 2 ); | |
add_filter( 'json_post_type_data', array( $wp_json_taxonomies, 'add_taxonomy_data' ), 10, 2 ); | |
add_filter( 'json_prepare_post', array( $wp_json_taxonomies, 'add_term_data' ), 10, 3 ); | |
// Fire off the request | |
// as per original php | |
$wp_json_server->serve_request(); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment