<!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>[43087] trunk: REST API: Filter responses based on the `_fields` parameter, before data is processed.</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 { white-space: pre-line; 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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/43087">43087</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/43087","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-05-02 01:24:30 +0000 (Wed, 02 May 2018)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>REST API: Filter responses based on the `_fields` parameter, before data is processed.

Historically, the REST API would generate the entire response object, including running expensive filters, then it would apply the `_fields` parameter, discarding the fields that weren't specificed.

This change causes `_fields` to be applied earlier, so that only requested fields are processed.

Props danielbachhuber.
See <a href="https://core.trac.wordpress.org/ticket/43874">#43874</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestattachmentscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestcommentscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestcontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpoststatusescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestposttypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestrevisionscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttaxonomiescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestuserscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestattachmentscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcategoriescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcommentscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpagescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpoststatusescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestposttypescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpostscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestrevisionscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiresttagscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapiresttaxonomiescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestuserscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-users-controller.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswprestattachmentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php 2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php   2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -284,62 +284,84 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $post, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $response = parent::prepare_item_for_response( $post, $request );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $fields   = $this->get_fields_for_response( $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $data     = $response->get_data();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data['description'] = array(
-                       'raw'      => $post->post_content,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'description', $fields, true ) ) {
+                       $data['description'] = array(
+                               'raw'      => $post->post_content,
+                               /** This filter is documented in wp-includes/post-template.php */
+                               'rendered' => apply_filters( 'the_content', $post->post_content ),
+                       );
+               }
+
+               if ( in_array( 'caption', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         /** This filter is documented in wp-includes/post-template.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'rendered' => apply_filters( 'the_content', $post->post_content ),
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $caption         = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
+                       $data['caption'] = array(
+                               'raw'      => $post->post_excerpt,
+                               'rendered' => $caption,
+                       );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                /** This filter is documented in wp-includes/post-template.php */
-               $caption         = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
-               $data['caption'] = array(
-                       'raw'      => $post->post_excerpt,
-                       'rendered' => $caption,
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'alt_text', $fields, true ) ) {
+                       $data['alt_text'] = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data['alt_text']      = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
-               $data['media_type']    = wp_attachment_is_image( $post->ID ) ? 'image' : 'file';
-               $data['mime_type']     = $post->post_mime_type;
-               $data['media_details'] = wp_get_attachment_metadata( $post->ID );
-               $data['post']          = ! empty( $post->post_parent ) ? (int) $post->post_parent : null;
-               $data['source_url']    = wp_get_attachment_url( $post->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'media_type', $fields, true ) ) {
+                       $data['media_type'] = wp_attachment_is_image( $post->ID ) ? 'image' : 'file';
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Ensure empty details is an empty object.
-               if ( empty( $data['media_details'] ) ) {
-                       $data['media_details'] = new stdClass;
-               } elseif ( ! empty( $data['media_details']['sizes'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'mime_type', $fields, true ) ) {
+                       $data['mime_type'] = $post->post_mime_type;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        foreach ( $data['media_details']['sizes'] as $size => &$size_data ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'media_details', $fields, true ) ) {
+                       $data['media_details'] = wp_get_attachment_metadata( $post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( isset( $size_data['mime-type'] ) ) {
-                                       $size_data['mime_type'] = $size_data['mime-type'];
-                                       unset( $size_data['mime-type'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Ensure empty details is an empty object.
+                       if ( empty( $data['media_details'] ) ) {
+                               $data['media_details'] = new stdClass;
+                       } elseif ( ! empty( $data['media_details']['sizes'] ) ) {
+
+                               foreach ( $data['media_details']['sizes'] as $size => &$size_data ) {
+
+                                       if ( isset( $size_data['mime-type'] ) ) {
+                                               $size_data['mime_type'] = $size_data['mime-type'];
+                                               unset( $size_data['mime-type'] );
+                                       }
+
+                                       // Use the same method image_downsize() does.
+                                       $image_src = wp_get_attachment_image_src( $post->ID, $size );
+                                       if ( ! $image_src ) {
+                                               continue;
+                                       }
+
+                                       $size_data['source_url'] = $image_src[0];
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // Use the same method image_downsize() does.
-                               $image_src = wp_get_attachment_image_src( $post->ID, $size );
-                               if ( ! $image_src ) {
-                                       continue;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $full_src = wp_get_attachment_image_src( $post->ID, 'full' );
+
+                               if ( ! empty( $full_src ) ) {
+                                       $data['media_details']['sizes']['full'] = array(
+                                               'file'       => wp_basename( $full_src[0] ),
+                                               'width'      => $full_src[1],
+                                               'height'     => $full_src[2],
+                                               'mime_type'  => $post->post_mime_type,
+                                               'source_url' => $full_src[0],
+                                       );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                               $size_data['source_url'] = $image_src[0];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } else {
+                               $data['media_details']['sizes'] = new stdClass;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $full_src = wp_get_attachment_image_src( $post->ID, 'full' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'post', $fields, true ) ) {
+                       $data['post'] = ! empty( $post->post_parent ) ? (int) $post->post_parent : null;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! empty( $full_src ) ) {
-                               $data['media_details']['sizes']['full'] = array(
-                                       'file'       => wp_basename( $full_src[0] ),
-                                       'width'      => $full_src[1],
-                                       'height'     => $full_src[2],
-                                       'mime_type'  => $post->post_mime_type,
-                                       'source_url' => $full_src[0],
-                               );
-                       }
-               } else {
-                       $data['media_details']['sizes'] = new stdClass;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'source_url', $fields, true ) ) {
+                       $data['source_url'] = wp_get_attachment_url( $post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestcommentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php    2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php      2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -862,35 +862,79 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return WP_REST_Response Response object.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $comment, $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = array(
-                       'id'                => (int) $comment->comment_ID,
-                       'post'              => (int) $comment->comment_post_ID,
-                       'parent'            => (int) $comment->comment_parent,
-                       'author'            => (int) $comment->user_id,
-                       'author_name'       => $comment->comment_author,
-                       'author_email'      => $comment->comment_author_email,
-                       'author_url'        => $comment->comment_author_url,
-                       'author_ip'         => $comment->comment_author_IP,
-                       'author_user_agent' => $comment->comment_agent,
-                       'date'              => mysql_to_rfc3339( $comment->comment_date ),
-                       'date_gmt'          => mysql_to_rfc3339( $comment->comment_date_gmt ),
-                       'content'           => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $fields = $this->get_fields_for_response( $request );
+               $data   = array();
+
+               if ( in_array( 'id', $fields, true ) ) {
+                       $data['id'] = (int) $comment->comment_ID;
+               }
+
+               if ( in_array( 'post', $fields, true ) ) {
+                       $data['post'] = (int) $comment->comment_post_ID;
+               }
+
+               if ( in_array( 'parent', $fields, true ) ) {
+                       $data['parent'] = (int) $comment->comment_parent;
+               }
+
+               if ( in_array( 'author', $fields, true ) ) {
+                       $data['author'] = (int) $comment->user_id;
+               }
+
+               if ( in_array( 'author_name', $fields, true ) ) {
+                       $data['author_name'] = $comment->comment_author;
+               }
+
+               if ( in_array( 'author_email', $fields, true ) ) {
+                       $data['author_email'] = $comment->comment_author_email;
+               }
+
+               if ( in_array( 'author_url', $fields, true ) ) {
+                       $data['author_url'] = $comment->comment_author_url;
+               }
+
+               if ( in_array( 'author_ip', $fields, true ) ) {
+                       $data['author_ip'] = $comment->comment_author_IP;
+               }
+
+               if ( in_array( 'author_user_agent', $fields, true ) ) {
+                       $data['author_user_agent'] = $comment->comment_agent;
+               }
+
+               if ( in_array( 'date', $fields, true ) ) {
+                       $data['date'] = mysql_to_rfc3339( $comment->comment_date );
+               }
+
+               if ( in_array( 'date_gmt', $fields, true ) ) {
+                       $data['date_gmt'] = mysql_to_rfc3339( $comment->comment_date_gmt );
+               }
+
+               if ( in_array( 'content', $fields, true ) ) {
+                       $data['content'] = array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 /** This filter is documented in wp-includes/comment-template.php */
</span><span class="cx" style="display: block; padding: 0 10px">                                'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'raw'      => $comment->comment_content,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        ),
-                       'link'              => get_comment_link( $comment ),
-                       'status'            => $this->prepare_status_response( $comment->comment_approved ),
-                       'type'              => get_comment_type( $comment->comment_ID ),
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $schema = $this->get_item_schema();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'link', $fields, true ) ) {
+                       $data['link'] = get_comment_link( $comment );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['author_avatar_urls'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'status', $fields, true ) ) {
+                       $data['status'] = $this->prepare_status_response( $comment->comment_approved );
+               }
+
+               if ( in_array( 'type', $fields, true ) ) {
+                       $data['type'] = get_comment_type( $comment->comment_ID );
+               }
+
+               if ( in_array( 'author_avatar_urls', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['author_avatar_urls'] = rest_get_avatar_urls( $comment->comment_author_email );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['meta'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'meta', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['meta'] = $this->meta->get_value( $comment->comment_ID, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php     2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php       2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -506,6 +506,35 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Gets an array of fields to be included on the response.
+        *
+        * Included fields are based on item schema and `_fields=` request argument.
+        *
+        * @since 4.9.6
+        *
+        * @param WP_REST_Request $request Full details about the request.
+        * @return array Fields to be included in the response.
+        */
+       public function get_fields_for_response( $request ) {
+               $schema = $this->get_item_schema();
+               $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array();
+               if ( ! isset( $request['_fields'] ) ) {
+                       return $fields;
+               }
+               $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
+               if ( 0 === count( $requested_fields ) ) {
+                       return $fields;
+               }
+               // Trim off outside whitespace from the comma delimited list.
+               $requested_fields = array_map( 'trim', $requested_fields );
+               // Always persist 'id', because it can be needed for add_additional_fields_to_object().
+               if ( in_array( 'id', $fields, true ) ) {
+                       $requested_fields[] = 'id';
+               }
+               return array_intersect( $fields, $requested_fields );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Retrieves an array of endpoint arguments from the item schema for the controller.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.7.0
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpoststatusescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php       2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php 2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -199,16 +199,37 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $status, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = array(
-                       'name'         => $status->label,
-                       'private'      => (bool) $status->private,
-                       'protected'    => (bool) $status->protected,
-                       'public'       => (bool) $status->public,
-                       'queryable'    => (bool) $status->publicly_queryable,
-                       'show_in_list' => (bool) $status->show_in_admin_all_list,
-                       'slug'         => $status->name,
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
+               $data   = array();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( in_array( 'name', $fields, true ) ) {
+                       $data['name'] = $status->label;
+               }
+
+               if ( in_array( 'private', $fields, true ) ) {
+                       $data['private'] = (bool) $status->private;
+               }
+
+               if ( in_array( 'protected', $fields, true ) ) {
+                       $data['protected'] = (bool) $status->protected;
+               }
+
+               if ( in_array( 'public', $fields, true ) ) {
+                       $data['public'] = (bool) $status->public;
+               }
+
+               if ( in_array( 'queryable', $fields, true ) ) {
+                       $data['queryable'] = (bool) $status->publicly_queryable;
+               }
+
+               if ( in_array( 'show_in_list', $fields, true ) ) {
+                       $data['show_in_list'] = (bool) $status->show_in_admin_all_list;
+               }
+
+               if ( in_array( 'slug', $fields, true ) ) {
+                       $data['slug'] = $status->name;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
</span><span class="cx" style="display: block; padding: 0 10px">                $data    = $this->add_additional_fields_to_object( $data, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $data    = $this->filter_response_by_context( $data, $context );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestposttypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php  2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php    2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -155,18 +155,49 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $base       = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
</span><span class="cx" style="display: block; padding: 0 10px">                $supports   = get_all_post_type_supports( $post_type->name );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data    = array(
-                       'capabilities' => $post_type->cap,
-                       'description'  => $post_type->description,
-                       'hierarchical' => $post_type->hierarchical,
-                       'viewable'     => is_post_type_viewable( $post_type ),
-                       'labels'       => $post_type->labels,
-                       'name'         => $post_type->label,
-                       'slug'         => $post_type->name,
-                       'supports'     => $supports,
-                       'taxonomies'   => array_values( $taxonomies ),
-                       'rest_base'    => $base,
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
+               $data   = array();
+
+               if ( in_array( 'capabilities', $fields, true ) ) {
+                       $data['capabilities'] = $post_type->cap;
+               }
+
+               if ( in_array( 'description', $fields, true ) ) {
+                       $data['description'] = $post_type->description;
+               }
+
+               if ( in_array( 'hierarchical', $fields, true ) ) {
+                       $data['hierarchical'] = $post_type->hierarchical;
+               }
+
+               if ( in_array( 'viewable', $fields, true ) ) {
+                       $data['viewable'] = is_post_type_viewable( $post_type );
+               }
+
+               if ( in_array( 'labels', $fields, true ) ) {
+                       $data['labels'] = $post_type->labels;
+               }
+
+               if ( in_array( 'name', $fields, true ) ) {
+                       $data['name'] = $post_type->label;
+               }
+
+               if ( in_array( 'slug', $fields, true ) ) {
+                       $data['slug'] = $post_type->name;
+               }
+
+               if ( in_array( 'supports', $fields, true ) ) {
+                       $data['supports'] = $supports;
+               }
+
+               if ( in_array( 'taxonomies', $fields, true ) ) {
+                       $data['taxonomies'] = array_values( $taxonomies );
+               }
+
+               if ( in_array( 'rest_base', $fields, true ) ) {
+                       $data['rest_base'] = $base;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
</span><span class="cx" style="display: block; padding: 0 10px">                $data    = $this->add_additional_fields_to_object( $data, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $data    = $this->filter_response_by_context( $data, $context );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php       2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1408,20 +1408,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                setup_postdata( $post );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $schema = $this->get_item_schema();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Base fields for every post.
</span><span class="cx" style="display: block; padding: 0 10px">                $data = array();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['id'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'id', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['id'] = $post->ID;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['date'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'date', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['date_gmt'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'date_gmt', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // For drafts, `post_date_gmt` may not be set, indicating that the
</span><span class="cx" style="display: block; padding: 0 10px">                        // date of the draft should be updated each time it is saved (see
</span><span class="cx" style="display: block; padding: 0 10px">                        // #38883).  In this case, shim the value based on the `post_date`
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1434,7 +1434,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['date_gmt'] = $this->prepare_date_response( $post_date_gmt );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['guid'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'guid', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['guid'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                /** This filter is documented in wp-includes/post-template.php */
</span><span class="cx" style="display: block; padding: 0 10px">                                'rendered' => apply_filters( 'get_the_guid', $post->guid, $post->ID ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1442,11 +1442,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['modified'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'modified', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['modified_gmt'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'modified_gmt', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // For drafts, `post_modified_gmt` may not be set (see
</span><span class="cx" style="display: block; padding: 0 10px">                        // `post_date_gmt` comments above).  In this case, shim the value
</span><span class="cx" style="display: block; padding: 0 10px">                        // based on the `post_modified` field with the site's timezone
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1459,27 +1459,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['modified_gmt'] = $this->prepare_date_response( $post_modified_gmt );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['password'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'password', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['password'] = $post->post_password;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['slug'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'slug', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['slug'] = $post->post_name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['status'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'status', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['status'] = $post->post_status;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['type'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'type', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['type'] = $post->post_type;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['link'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'link', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['link'] = get_permalink( $post->ID );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['title'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'title', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['title'] = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1499,7 +1499,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $has_password_filter = true;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['content'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'content', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['content'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'raw'       => $post->post_content,
</span><span class="cx" style="display: block; padding: 0 10px">                                /** This filter is documented in wp-includes/post-template.php */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1508,7 +1508,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['excerpt'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'excerpt', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         /** This filter is documented in wp-includes/post-template.php */
</span><span class="cx" style="display: block; padding: 0 10px">                        $excerpt         = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['excerpt'] = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1523,35 +1523,35 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        remove_filter( 'post_password_required', '__return_false' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['author'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'author', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['author'] = (int) $post->post_author;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['featured_media'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'featured_media', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['featured_media'] = (int) get_post_thumbnail_id( $post->ID );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['parent'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'parent', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['parent'] = (int) $post->post_parent;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['menu_order'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'menu_order', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['menu_order'] = (int) $post->menu_order;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['comment_status'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'comment_status', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['comment_status'] = $post->comment_status;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['ping_status'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'ping_status', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['ping_status'] = $post->ping_status;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['sticky'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'sticky', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['sticky'] = is_sticky( $post->ID );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['template'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'template', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $template = get_page_template_slug( $post->ID ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $data['template'] = $template;
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1559,7 +1559,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['format'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'format', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['format'] = get_post_format( $post->ID );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Fill in blank post format.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1568,7 +1568,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['meta'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'meta', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['meta'] = $this->meta->get_value( $post->ID, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1577,7 +1577,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $taxonomies as $taxonomy ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! empty( $schema['properties'][ $base ] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( in_array( $base, $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $terms         = get_the_terms( $post, $taxonomy->name );
</span><span class="cx" style="display: block; padding: 0 10px">                                $data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array();
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php   2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php     2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -340,43 +340,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                setup_postdata( $post );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $schema = $this->get_item_schema();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
+               $data   = array();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = array();
-
-               if ( ! empty( $schema['properties']['author'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'author', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['author'] = (int) $post->post_author;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['date'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'date', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['date_gmt'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'date_gmt', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['id'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'id', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['id'] = $post->ID;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['modified'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'modified', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['modified_gmt'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'modified_gmt', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['parent'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'parent', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['parent'] = (int) $post->post_parent;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['slug'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'slug', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['slug'] = $post->post_name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['guid'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'guid', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['guid'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                /** This filter is documented in wp-includes/post-template.php */
</span><span class="cx" style="display: block; padding: 0 10px">                                'rendered' => apply_filters( 'get_the_guid', $post->guid, $post->ID ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -384,7 +383,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['title'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'title', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['title'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'raw'      => $post->post_title,
</span><span class="cx" style="display: block; padding: 0 10px">                                'rendered' => get_the_title( $post->ID ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -391,7 +390,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['content'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'content', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['content'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'raw'      => $post->post_content,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -400,7 +399,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['excerpt'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'excerpt', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['excerpt'] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'raw'      => $post->post_excerpt,
</span><span class="cx" style="display: block; padding: 0 10px">                                'rendered' => $this->prepare_excerpt_response( $post->post_excerpt, $post ),
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttaxonomiescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php  2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php    2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,17 +181,48 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $taxonomy, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = array(
-                       'name'         => $taxonomy->label,
-                       'slug'         => $taxonomy->name,
-                       'capabilities' => $taxonomy->cap,
-                       'description'  => $taxonomy->description,
-                       'labels'       => $taxonomy->labels,
-                       'types'        => $taxonomy->object_type,
-                       'show_cloud'   => $taxonomy->show_tagcloud,
-                       'hierarchical' => $taxonomy->hierarchical,
-                       'rest_base'    => $base,
-                       'visibility'   => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $fields = $this->get_fields_for_response( $request );
+               $data   = array();
+
+               if ( in_array( 'name', $fields, true ) ) {
+                       $data['name'] = $taxonomy->label;
+               }
+
+               if ( in_array( 'slug', $fields, true ) ) {
+                       $data['slug'] = $taxonomy->name;
+               }
+
+               if ( in_array( 'capabilities', $fields, true ) ) {
+                       $data['capabilities'] = $taxonomy->cap;
+               }
+
+               if ( in_array( 'description', $fields, true ) ) {
+                       $data['description'] = $taxonomy->description;
+               }
+
+               if ( in_array( 'labels', $fields, true ) ) {
+                       $data['labels'] = $taxonomy->labels;
+               }
+
+               if ( in_array( 'types', $fields, true ) ) {
+                       $data['types'] = $taxonomy->object_type;
+               }
+
+               if ( in_array( 'show_cloud', $fields, true ) ) {
+                       $data['show_cloud'] = $taxonomy->show_tagcloud;
+               }
+
+               if ( in_array( 'hierarchical', $fields, true ) ) {
+                       $data['hierarchical'] = $taxonomy->hierarchical;
+               }
+
+               if ( in_array( 'rest_base', $fields, true ) ) {
+                       $data['rest_base'] = $base;
+               }
+
+               if ( in_array( 'visibility', $fields, true ) ) {
+                       $data['visibility'] = array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'public'             => (bool) $taxonomy->public,
</span><span class="cx" style="display: block; padding: 0 10px">                                'publicly_queryable' => (bool) $taxonomy->publicly_queryable,
</span><span class="cx" style="display: block; padding: 0 10px">                                'show_admin_column'  => (bool) $taxonomy->show_admin_column,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -198,8 +229,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'show_in_nav_menus'  => (bool) $taxonomy->show_in_nav_menus,
</span><span class="cx" style="display: block; padding: 0 10px">                                'show_in_quick_edit' => (bool) $taxonomy->show_in_quick_edit,
</span><span class="cx" style="display: block; padding: 0 10px">                                'show_ui'            => (bool) $taxonomy->show_ui,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        ),
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
</span><span class="cx" style="display: block; padding: 0 10px">                $data    = $this->add_additional_fields_to_object( $data, $request );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php       2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php 2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -691,42 +691,42 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $item, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $schema = $this->get_item_schema();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $data   = array();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['id'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'id', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['id'] = (int) $item->term_id;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['count'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'count', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['count'] = (int) $item->count;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['description'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'description', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['description'] = $item->description;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['link'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'link', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['link'] = get_term_link( $item );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['name'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'name', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['name'] = $item->name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['slug'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'slug', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['slug'] = $item->slug;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['taxonomy'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'taxonomy', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['taxonomy'] = $item->taxonomy;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['parent'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'parent', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['parent'] = (int) $item->parent;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['meta'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'meta', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['meta'] = $this->meta->get_value( $item->term_id, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestuserscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php       2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php 2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -846,78 +846,78 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $user, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $data   = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $schema = $this->get_item_schema();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['id'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'id', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['id'] = $user->ID;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['username'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'username', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['username'] = $user->user_login;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['name'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'name', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['name'] = $user->display_name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['first_name'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'first_name', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['first_name'] = $user->first_name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['last_name'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'last_name', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['last_name'] = $user->last_name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['email'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'email', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['email'] = $user->user_email;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['url'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'url', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['url'] = $user->user_url;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['description'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'description', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['description'] = $user->description;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['link'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'link', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['link'] = get_author_posts_url( $user->ID, $user->user_nicename );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['locale'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'locale', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['locale'] = get_user_locale( $user );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['nickname'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'nickname', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['nickname'] = $user->nickname;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['slug'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'slug', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['slug'] = $user->user_nicename;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['roles'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'roles', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Defensively call array_values() to ensure an array is returned.
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['roles'] = array_values( $user->roles );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['registered_date'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'registered_date', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['registered_date'] = date( 'c', strtotime( $user->user_registered ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['capabilities'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'capabilities', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['capabilities'] = (object) $user->allcaps;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['extra_capabilities'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'extra_capabilities', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['extra_capabilities'] = (object) $user->caps;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['avatar_urls'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'avatar_urls', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['avatar_urls'] = rest_get_avatar_urls( $user->user_email );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $schema['properties']['meta'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( 'meta', $fields, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['meta'] = $this->meta->get_value( $user->ID, $request );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestattachmentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php        2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php  2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1178,6 +1178,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_post_data( $attachment, $data, 'embed', $response->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               $attachment_id = $this->factory->attachment->create_object(
+                       $this->test_file, 0, array(
+                               'post_mime_type' => 'image/jpeg',
+                               'post_excerpt'   => 'A sample caption',
+                               'post_author'    => self::$editor_id,
+                       )
+               );
+               wp_set_current_user( self::$editor_id );
+               $endpoint = new WP_REST_Attachments_Controller( 'post' );
+               $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) );
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,slug' );
+               $obj      = get_post( $attachment_id );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'slug',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcategoriescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php 2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php   2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -882,6 +882,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_taxonomy_term( $term, $data, $response->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               $request  = new WP_REST_Request;
+               $endpoint = new WP_REST_Terms_Controller( 'category' );
+               $request->set_param( '_fields', 'id,name' );
+               $term     = get_term( 1, 'category' );
+               $response = $endpoint->prepare_item_for_response( $term, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'name',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_prepare_taxonomy_term_child() {
</span><span class="cx" style="display: block; padding: 0 10px">                $child = $this->factory->category->create(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcommentscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php   2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php     2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -847,6 +847,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_comment_data( $data, 'edit', $response->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               wp_set_current_user( self::$admin_id );
+               $endpoint = new WP_REST_Comments_Controller;
+               $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,status' );
+               $obj      = get_comment( self::$approved_id );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'status',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_comment_author_avatar_urls() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-controller.php    2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-controller.php      2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -200,4 +200,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'a', $args['somedefault']['default'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       public function test_get_fields_for_response() {
+               $controller = new WP_REST_Test_Controller();
+               $request    = new WP_REST_Request( 'GET', '/wp/v2/testroute' );
+               $fields     = $controller->get_fields_for_response( $request );
+               $this->assertEquals( array(
+                       'somestring',
+                       'someinteger',
+                       'someboolean',
+                       'someurl',
+                       'somedate',
+                       'someemail',
+                       'someenum',
+                       'someargoptions',
+                       'somedefault',
+               ), $fields );
+               $request->set_param( '_fields', 'somestring,someinteger' );
+               $fields = $controller->get_fields_for_response( $request );
+               $this->assertEquals( array(
+                       'somestring',
+                       'someinteger',
+               ), $fields );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpagescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php      2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php        2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -451,6 +451,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               wp_set_current_user( self::$editor_id );
+               $page_id  = $this->factory->post->create(
+                       array(
+                               'post_status' => 'publish',
+                               'post_type'   => 'page',
+                       )
+               );
+               $endpoint = new WP_REST_Posts_Controller( 'page' );
+               $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,slug' );
+               $obj      = get_post( $page_id );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'slug',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_pages_params() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->factory->post->create_many(
</span><span class="cx" style="display: block; padding: 0 10px">                        8, array(
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpoststatusescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php      2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php        2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -131,6 +131,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_post_status_obj( $obj, $data->get_data(), $data->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               $obj      = get_post_status_object( 'publish' );
+               $request  = new WP_REST_Request;
+               $endpoint = new WP_REST_Post_Statuses_Controller;
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,name' );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertEquals( array(
+                       // 'id' doesn't exist in this context.
+                       'name',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestposttypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php 2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php   2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -123,6 +123,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_post_type_obj( 'edit', $obj, $response->get_data(), $response->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               $obj      = get_post_type_object( 'post' );
+               $request  = new WP_REST_Request;
+               $endpoint = new WP_REST_Post_Types_Controller;
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,name' );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertEquals( array(
+                       // 'id' doesn't exist in this context.
+                       'name',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php      2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php        2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1499,6 +1499,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_get_post_response( $response, 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               wp_set_current_user( self::$editor_id );
+               $endpoint = new WP_REST_Posts_Controller( 'post' );
+               $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,slug' );
+               $obj      = get_post( self::$post_id );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'slug',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_create_item() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$editor_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestrevisionscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php  2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php    2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -237,6 +237,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_get_revision_response( $response, $this->revision_1 );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               wp_set_current_user( self::$editor_id );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
+               $endpoint = new WP_REST_Revisions_Controller( 'post' );
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,slug' );
+               $revision = get_post( $this->revision_id1 );
+               $response = $endpoint->prepare_item_for_response( $revision, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'slug',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiresttagscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php       2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php 2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -968,6 +968,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_taxonomy_term( $term, $data, $response->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               $request  = new WP_REST_Request;
+               $endpoint = new WP_REST_Terms_Controller( 'post_tag' );
+               $request->set_param( '_fields', 'id,name' );
+               $term     = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
+               $response = $endpoint->prepare_item_for_response( $term, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'name',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiresttaxonomiescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php 2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php   2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -162,6 +162,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_taxonomy_object( 'edit', $tax, $response->get_data(), $response->get_links() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               $tax      = get_taxonomy( 'category' );
+               $request  = new WP_REST_Request;
+               $endpoint = new WP_REST_Taxonomies_Controller;
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,name' );
+               $response = $endpoint->prepare_item_for_response( $tax, $request );
+               $this->assertEquals( array(
+                       // 'id' doesn't exist in this context.
+                       'name',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' );
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestuserscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-users-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-users-controller.php      2018-05-02 01:07:43 UTC (rev 43086)
+++ trunk/tests/phpunit/tests/rest-api/rest-users-controller.php        2018-05-02 01:24:30 UTC (rev 43087)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -849,6 +849,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->check_get_user_response( $data, 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_prepare_item_limit_fields() {
+               wp_set_current_user( self::$user );
+               $request = new WP_REST_Request;
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,name' );
+               $user     = get_user_by( 'id', get_current_user_id() );
+               $response = $this->endpoint->prepare_item_for_response( $user, $request );
+               $this->assertEquals( array(
+                       'id',
+                       'name',
+               ), array_keys( $response->get_data() ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_user_avatar_urls() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$user );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre>
</div>
</div>

</body>
</html>