<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2277] 2013/rmccue/trunk: Separate each set of endpoints via filters</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://gsoc.trac.wordpress.org/changeset/2277">2277</a></dd>
<dt>Author</dt> <dd>rmccue</dd>
<dt>Date</dt> <dd>2013-09-11 07:02:57 +0000 (Wed, 11 Sep 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Separate each set of endpoints via filters

This creates a much larger separation between the different post types, and is
more indicative of how these should be used in plugins.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#2013rmccuetrunklibclasswpjsonmediaphp">2013/rmccue/trunk/lib/class-wp-json-media.php</a></li>
<li><a href="#2013rmccuetrunklibclasswpjsonpagesphp">2013/rmccue/trunk/lib/class-wp-json-pages.php</a></li>
<li><a href="#2013rmccuetrunklibclasswpjsonpostsphp">2013/rmccue/trunk/lib/class-wp-json-posts.php</a></li>
<li><a href="#2013rmccuetrunklibclasswpjsonserverphp">2013/rmccue/trunk/lib/class-wp-json-server.php</a></li>
<li><a href="#2013rmccuetrunkpluginphp">2013/rmccue/trunk/plugin.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013rmccuetrunklibclasswpjsonmediaphp"></a>
<div class="modfile"><h4>Modified: 2013/rmccue/trunk/lib/class-wp-json-media.php (2276 => 2277)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/rmccue/trunk/lib/class-wp-json-media.php    2013-09-11 07:02:51 UTC (rev 2276)
+++ 2013/rmccue/trunk/lib/class-wp-json-media.php       2013-09-11 07:02:57 UTC (rev 2277)
</span><span class="lines">@@ -2,6 +2,28 @@
</span><span class="cx"> 
</span><span class="cx"> class WP_JSON_Media extends WP_JSON_Posts {
</span><span class="cx">  /**
</span><ins>+        * Register the media-related routes
+        *
+        * @param array $routes Existing routes
+        * @return array Modified routes
+        */
+       public function registerRoutes( $routes ) {
+               $media_routes = array(
+                       '/media' => array(
+                               array( array( $this, 'getPosts' ),         WP_JSON_Server::READABLE ),
+                               array( array( $this, 'uploadAttachment' ), WP_JSON_Server::CREATABLE ),
+                       ),
+
+                       '/media/(?P<id>\d+)' => array(
+                               array( array( $this, 'getPost' ),    WP_JSON_Server::READABLE ),
+                               array( array( $this, 'editPost' ),   WP_JSON_Server::EDITABLE ),
+                               array( array( $this, 'deletePost' ), WP_JSON_Server::DELETABLE ),
+                       ),
+               );
+               return array_merge( $routes, $media_routes );
+       }
+
+       /**
</ins><span class="cx">    * Retrieve pages
</span><span class="cx">   *
</span><span class="cx">   * Overrides the $type to set to 'attachment', then passes through to the post
</span><span class="lines">@@ -290,4 +312,62 @@
</span><span class="cx"> 
</span><span class="cx">          return $file;
</span><span class="cx">  }
</span><ins>+
+       /**
+        * Check featured image data before creating/updating post
+        *
+        * @param bool|WP_Error $status Previous status
+        * @param array $post Post data to be inserted
+        * @param array $data Supplied post data
+        * @return bool|WP_Error Success or error object
+        */
+       public function preinsertCheck( $status, $post, $data ) {
+               if ( is_wp_error( $status ) ) {
+                       return $status;
+               }
+
+               // Featured image (pre-verification)
+               if ( ! empty( $data['featured_image'] ) ) {
+                       $thumbnail = $this->getPost( (int) $data['featured_image'], 'child' );
+                       if ( is_wp_error( $thumbnail ) ) {
+                               return new WP_Error( 'json_invalid_featured_image', __( 'Invalid featured image.' ), array( 'status' => 400 ) );
+                       }
+               }
+
+               return $status;
+       }
+
+       /**
+        * Set the featured image on post update
+        *
+        * @param array $post Post data
+        * @param array $data Supplied post data
+        * @param boolean $update Is this an update?
+        */
+       public function attachThumbnail( $post, $data, $update ) {
+               if ( ! empty( $data['featured_image'] ) ) {
+                       // Already verified in preinsertCheck()
+                       $thumbnail = $this->getPost( $data['featured_image'], 'child' );
+                       set_post_thumbnail( $post_ID, $thumbnail['ID'] );
+               }
+       }
+
+       /**
+        * Add the featured image data to the post data
+        *
+        * @param array $data Post data
+        * @param array $post Raw post data from the database
+        * @param string $context Display context
+        * @return array Filtered post data
+        */
+       public function addThumbnailData( $data, $post, $context ) {
+               // Thumbnail
+               $data['featured_image'] = null;
+               $thumbnail_id = get_post_thumbnail_id( $post['ID'] );
+               if ( $thumbnail_id ) {
+                       $data['featured_image'] = $GLOBALS['wp_json_media']->getAttachment( $thumbnail_id, 'child' );
+               }
+
+               return $data;
+       }
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="2013rmccuetrunklibclasswpjsonpagesphp"></a>
<div class="modfile"><h4>Modified: 2013/rmccue/trunk/lib/class-wp-json-pages.php (2276 => 2277)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/rmccue/trunk/lib/class-wp-json-pages.php    2013-09-11 07:02:51 UTC (rev 2276)
+++ 2013/rmccue/trunk/lib/class-wp-json-pages.php       2013-09-11 07:02:57 UTC (rev 2277)
</span><span class="lines">@@ -20,6 +20,47 @@
</span><span class="cx">  */
</span><span class="cx"> class WP_JSON_Pages extends WP_JSON_Posts {
</span><span class="cx">  /**
</span><ins>+        * Register the page-related routes
+        *
+        * @param array $routes Existing routes
+        * @return array Modified routes
+        */
+       public function registerRoutes( $routes ) {
+               $page_routes = array(
+                       // Page endpoints
+                       '/pages'             => array(
+                               array( array( $this, 'getPosts' ), WP_JSON_Server::READABLE ),
+                               array( array( $this, 'newPost' ),  WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
+                       ),
+
+                       '/pages/(?P<id>\d+)' => array(
+                               array( array( $this, 'getPost' ),    WP_JSON_Server::READABLE ),
+                               array( array( $this, 'editPost' ),   WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
+                               array( array( $this, 'deletePost' ), WP_JSON_Server::DELETABLE ),
+                       ),
+                       '/pages/(?P<path>.+)' => array(
+                               array( array( $this, 'getPostByPath' ),    WP_JSON_Server::READABLE ),
+                               array( array( $this, 'editPostByPath' ),   WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
+                               array( array( $this, 'deletePostByPath' ), WP_JSON_Server::DELETABLE ),
+                       ),
+
+                       '/pages/(?P<id>\d+)/revisions' => array( '__return_null', WP_JSON_Server::READABLE ),
+
+                       // Page comments
+                       '/pages/(?P<id>\d+)/comments'                  => array(
+                               array( array( $this, 'getComments' ), WP_JSON_Server::READABLE ),
+                               array( '__return_null', WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
+                       ),
+                       '/pages/(?P<id>\d+)/comments/(?P<comment>\d+)' => array(
+                               array( array( $this, 'getComment' ), WP_JSON_Server::READABLE ),
+                               array( '__return_null', WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
+                               array( '__return_null', WP_JSON_Server::DELETABLE ),
+                       ),
+               );
+               return array_merge( $routes, $page_routes );
+       }
+
+       /**
</ins><span class="cx">    * Retrieve pages
</span><span class="cx">   *
</span><span class="cx">   * Overrides the $type to set to 'page', then passes through to the post
</span></span></pre></div>
<a id="2013rmccuetrunklibclasswpjsonpostsphp"></a>
<div class="modfile"><h4>Modified: 2013/rmccue/trunk/lib/class-wp-json-posts.php (2276 => 2277)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/rmccue/trunk/lib/class-wp-json-posts.php    2013-09-11 07:02:51 UTC (rev 2276)
+++ 2013/rmccue/trunk/lib/class-wp-json-posts.php       2013-09-11 07:02:57 UTC (rev 2277)
</span><span class="lines">@@ -2,6 +2,46 @@
</span><span class="cx"> 
</span><span class="cx"> class WP_JSON_Posts {
</span><span class="cx">  /**
</span><ins>+        * Register the post-related routes
+        *
+        * @param array $routes Existing routes
+        * @return array Modified routes
+        */
+       public function registerRoutes( $routes ) {
+               $post_routes = array(
+                       // Post endpoints
+                       '/posts'             => array(
+                               array( array( $this, 'getPosts' ), WP_JSON_Server::READABLE ),
+                               array( array( $this, 'newPost' ),  WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
+                       ),
+
+                       '/posts/(?P<id>\d+)' => array(
+                               array( array( $this, 'getPost' ),    WP_JSON_Server::READABLE ),
+                               array( array( $this, 'editPost' ),   WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
+                               array( array( $this, 'deletePost' ), WP_JSON_Server::DELETABLE ),
+                       ),
+                       '/posts/(?P<id>\d+)/revisions' => array( '__return_null', WP_JSON_Server::READABLE ),
+
+                       // Comments
+                       '/posts/(?P<id>\d+)/comments'                  => array(
+                               array( array( $this, 'getComments' ), WP_JSON_Server::READABLE ),
+                               array( '__return_null', WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ),
+                       ),
+                       '/posts/(?P<id>\d+)/comments/(?P<comment>\d+)' => array(
+                               array( array( $this, 'getComment' ), WP_JSON_Server::READABLE ),
+                               array( '__return_null', WP_JSON_Server::EDITABLE | WP_JSON_Server::ACCEPT_JSON ),
+                               array( '__return_null', WP_JSON_Server::DELETABLE ),
+                       ),
+
+                       // Meta-post endpoints
+                       '/posts/types'               => array( array( $this, 'getPostTypes' ), WP_JSON_Server::READABLE ),
+                       '/posts/types/(?P<type>\w+)' => array( array( $this, 'getPostType' ), WP_JSON_Server::READABLE ),
+                       '/posts/statuses'            => array( array( $this, 'getPostStatuses' ), WP_JSON_Server::READABLE ),
+               );
+               return array_merge( $routes, $post_routes );
+       }
+
+       /**
</ins><span class="cx">    * Retrieve posts.
</span><span class="cx">   *
</span><span class="cx">   * @since 3.4.0
</span><span class="lines">@@ -456,13 +496,6 @@
</span><span class="cx">                  $post_fields_extended['password'] = $post['post_password'];
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               // Thumbnail
-               $post_fields_extended['featured_image'] = null;
-               $thumbnail_id = get_post_thumbnail_id( $post['ID'] );
-               if ( $thumbnail_id ) {
-                       $post_fields_extended['featured_image'] = $GLOBALS['wp_json_media']->getAttachment( $thumbnail_id, 'child' );
-               }
-
</del><span class="cx">           // Consider future posts as published
</span><span class="cx">          if ( $post_fields['status'] === 'future' )
</span><span class="cx">                  $post_fields['status'] = 'publish';
</span><span class="lines">@@ -813,12 +846,10 @@
</span><span class="cx">                  $post['post_format'] = $data['post_format'];
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               // Featured image (pre-verification)
-               if ( ! empty( $data['featured_image'] ) ) {
-                       $thumbnail = $GLOBALS['wp_json_media']->getAttachment( $data['featured_image'], 'child' );
-                       if ( is_wp_error( $thumbnail ) ) {
-                               return new WP_Error( 'json_invalid_featured_image', __( 'Invalid featured image.' ), array( 'status' => 400 ) );
-                       }
</del><ins>+                // Pre-insert hook
+               $can_insert = apply_filters( 'json_pre_insert_post', true, $post, $data, $update );
+               if ( is_wp_error( $can_insert ) ) {
+                       return $can_insert;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          // Post meta
</span><span class="lines">@@ -840,11 +871,6 @@
</span><span class="cx">          // Terms
</span><span class="cx">          // TODO: implement this
</span><span class="cx"> 
</span><del>-               // Post thumbnail
-               if ( ! $thumbnail ) {
-                       set_post_thumbnail( $post_ID, $thumbnail['ID'] );
-               }
-
</del><span class="cx">           do_action( 'json_insert_post', $post, $data, $update );
</span><span class="cx"> 
</span><span class="cx">          return $post_ID;
</span></span></pre></div>
<a id="2013rmccuetrunklibclasswpjsonserverphp"></a>
<div class="modfile"><h4>Modified: 2013/rmccue/trunk/lib/class-wp-json-server.php (2276 => 2277)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/rmccue/trunk/lib/class-wp-json-server.php   2013-09-11 07:02:51 UTC (rev 2276)
+++ 2013/rmccue/trunk/lib/class-wp-json-server.php      2013-09-11 07:02:57 UTC (rev 2277)
</span><span class="lines">@@ -213,73 +213,10 @@
</span><span class="cx">   * @return array `'/path/regex' => array( $callback, $bitmask )` or `'/path/regex' => array( array( $callback, $bitmask ), ...)`
</span><span class="cx">   */
</span><span class="cx">  public function getRoutes() {
</span><del>-               $GLOBALS['wp_json_posts'] = $posts = new WP_JSON_Posts();
-               $GLOBALS['wp_json_pages'] = $pages = new WP_JSON_Pages();
-               $GLOBALS['wp_json_media'] = $media = new WP_JSON_Media();
-
</del><span class="cx">           $endpoints = array(
</span><span class="cx">                  // Meta endpoints
</span><span class="cx">                  '/' => array( array( $this, 'getIndex' ), self::READABLE ),
</span><span class="cx"> 
</span><del>-                       // Post endpoints
-                       '/posts'             => array(
-                               array( array( $posts, 'getPosts' ), self::READABLE ),
-                               array( array( $posts, 'newPost' ),  self::CREATABLE | self::ACCEPT_JSON ),
-                       ),
-
-                       '/posts/(?P<id>\d+)' => array(
-                               array( array( $posts, 'getPost' ),    self::READABLE ),
-                               array( array( $posts, 'editPost' ),   self::EDITABLE | self::ACCEPT_JSON ),
-                               array( array( $posts, 'deletePost' ), self::DELETABLE ),
-                       ),
-                       '/posts/(?P<id>\d+)/revisions' => array( '__return_null', self::READABLE ),
-
-                       // Comments
-                       '/posts/(?P<id>\d+)/comments'                  => array(
-                               array( array( $posts, 'getComments' ), self::READABLE ),
-                               array( '__return_null', self::CREATABLE | self::ACCEPT_JSON ),
-                       ),
-                       '/posts/(?P<id>\d+)/comments/(?P<comment>\d+)' => array(
-                               array( array( $posts, 'getComment' ), self::READABLE ),
-                               array( '__return_null', self::EDITABLE | self::ACCEPT_JSON ),
-                               array( '__return_null', self::DELETABLE ),
-                       ),
-
-                       // Meta-post endpoints
-                       '/posts/types'               => array( array( $posts, 'getPostTypes' ), self::READABLE ),
-                       '/posts/types/(?P<type>\w+)' => array( array( $posts, 'getPostType' ), self::READABLE ),
-                       '/posts/statuses'            => array( array( $posts, 'getPostStatuses' ), self::READABLE ),
-
-                       // Page endpoints
-                       '/pages'             => array(
-                               array( array( $pages, 'getPosts' ), self::READABLE ),
-                               array( array( $pages, 'newPost' ),  self::CREATABLE | self::ACCEPT_JSON ),
-                       ),
-
-                       '/pages/(?P<id>\d+)' => array(
-                               array( array( $pages, 'getPost' ),    self::READABLE ),
-                               array( array( $pages, 'editPost' ),   self::EDITABLE | self::ACCEPT_JSON ),
-                               array( array( $pages, 'deletePost' ), self::DELETABLE ),
-                       ),
-                       '/pages/(?P<path>.+)' => array(
-                               array( array( $pages, 'getPostByPath' ),    self::READABLE ),
-                               array( array( $pages, 'editPostByPath' ),   self::EDITABLE | self::ACCEPT_JSON ),
-                               array( array( $pages, 'deletePostByPath' ), self::DELETABLE ),
-                       ),
-
-                       '/pages/(?P<id>\d+)/revisions' => array( '__return_null', self::READABLE ),
-
-                       // Page comments
-                       '/pages/(?P<id>\d+)/comments'                  => array(
-                               array( array( $pages, 'getComments' ), self::READABLE ),
-                               array( '__return_null', self::CREATABLE | self::ACCEPT_JSON ),
-                       ),
-                       '/pages/(?P<id>\d+)/comments/(?P<comment>\d+)' => array(
-                               array( array( $pages, 'getComment' ), self::READABLE ),
-                               array( '__return_null', self::EDITABLE | self::ACCEPT_JSON ),
-                               array( '__return_null', self::DELETABLE ),
-                       ),
-
</del><span class="cx">                   // Taxonomies
</span><span class="cx">                  '/taxonomies'                                       => array( '__return_null', self::READABLE ),
</span><span class="cx">                  '/taxonomies/(?P<taxonomy>\w+)'                     => array(
</span><span class="lines">@@ -308,17 +245,6 @@
</span><span class="cx">                          array( '__return_null', self::READABLE ),
</span><span class="cx">                          array( '__return_null', self::CREATABLE | self::ACCEPT_JSON ),
</span><span class="cx">                  ),
</span><del>-
-                       '/media' => array(
-                               array( array( $media, 'getPosts' ),   self::READABLE ),
-                               array( array( $media, 'uploadAttachment' ), self::CREATABLE ),
-                       ),
-
-                       '/media/(?P<id>\d+)' => array(
-                               array( array( $media, 'getPost' ),    self::READABLE ),
-                               array( array( $media, 'editPost' ),   self::EDITABLE ),
-                               array( array( $media, 'deletePost' ), self::DELETABLE ),
-                       ),
</del><span class="cx">           );
</span><span class="cx"> 
</span><span class="cx">          $endpoints = apply_filters( 'json_endpoints', $endpoints );
</span></span></pre></div>
<a id="2013rmccuetrunkpluginphp"></a>
<div class="modfile"><h4>Modified: 2013/rmccue/trunk/plugin.php (2276 => 2277)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/rmccue/trunk/plugin.php     2013-09-11 07:02:51 UTC (rev 2276)
+++ 2013/rmccue/trunk/plugin.php        2013-09-11 07:02:57 UTC (rev 2277)
</span><span class="lines">@@ -7,6 +7,9 @@
</span><span class="cx">  * Version: 0.5-dev
</span><span class="cx">  * Plugin URI: https://github.com/rmccue/WP-API
</span><span class="cx">  */
</span><ins>+include_once( dirname( __FILE__ ) . '/lib/class-wp-json-posts.php' );
+include_once( dirname( __FILE__ ) . '/lib/class-wp-json-pages.php' );
+include_once( dirname( __FILE__ ) . '/lib/class-wp-json-media.php' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Register our rewrite rules for the API
</span><span class="lines">@@ -21,6 +24,31 @@
</span><span class="cx"> add_action( 'init', 'json_api_init' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Register the default JSON API filters
+ *
+ * @internal This will live in default-filters.php
+ */
+function json_api_default_filters() {
+       global $wp_json_posts, $wp_json_pages, $wp_json_media;
+
+       // Posts
+       $wp_json_posts = new WP_JSON_Posts();
+       add_filter( 'json_endpoints', array( $wp_json_posts, 'registerRoutes' ) );
+
+       // Pages
+       $wp_json_pages = new WP_JSON_Pages();
+       add_filter( 'json_endpoints', array( $wp_json_pages, 'registerRoutes' ) );
+
+       // Media
+       $wp_json_media = new WP_JSON_Media();
+       add_filter( 'json_endpoints',       array( $wp_json_media, 'registerRoutes' ) );
+       add_filter( 'json_prepare_post',    array( $wp_json_media, 'addThumbnailData' ), 10, 3 );
+       add_filter( 'json_pre_insert_post', array( $wp_json_media, 'preinsertCheck' ),   10, 3 );
+       add_filter( 'json_insert_post',     array( $wp_json_media, 'attachThumbnail' ),  10, 3 );
+}
+add_action( 'plugins_loaded', 'json_api_default_filters' );
+
+/**
</ins><span class="cx">  * Load the JSON API
</span><span class="cx">  */
</span><span class="cx"> function json_api_loaded() {
</span><span class="lines">@@ -30,9 +58,6 @@
</span><span class="cx">  include_once( ABSPATH . WPINC . '/class-IXR.php' );
</span><span class="cx">  include_once( ABSPATH . WPINC . '/class-wp-xmlrpc-server.php' );
</span><span class="cx">  include_once( dirname( __FILE__ ) . '/lib/class-wp-json-server.php' );
</span><del>-       include_once( dirname( __FILE__ ) . '/lib/class-wp-json-posts.php' );
-       include_once( dirname( __FILE__ ) . '/lib/class-wp-json-pages.php' );
-       include_once( dirname( __FILE__ ) . '/lib/class-wp-json-media.php' );
</del><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Whether this is a XMLRPC Request
</span></span></pre>
</div>
</div>

</body>
</html>