Skip to content

@cgspicer /wp-json.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fishpig Wordpress integration extension patch of WP-API
<?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
Something went wrong with that request. Please try again.