<!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>[53760] trunk: REST API: Avoid unnecessarily preparing item links.</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/53760">53760</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/53760","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>spacedmonkey</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-07-22 13:58:46 +0000 (Fri, 22 Jul 2022)</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: Avoid unnecessarily preparing item links.

Do not call the `prepare_links` methods in core REST API controllers, unless the `_links` or `_embedded` fields are requested. There is no need to prepare links if they are never returned in the response. This saves resources, as many calls to `prepare_links` methods perform database queries. 

Props Spacedmonkey, timothyblynjacobs, rachelbaker, desrosj, dlh, hellofromTonya.
Fixes <a href="https://core.trac.wordpress.org/ticket/52992">#52992</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestapplicationpasswordscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestblockdirectorycontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestblocktypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-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="#trunksrcwpincludesrestapiendpointsclasswprestglobalstylescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestmenuitemscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestmenulocationscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestmenuscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpluginscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-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="#trunksrcwpincludesrestapiendpointsclasswprestsearchcontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestsidebarscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-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="#trunksrcwpincludesrestapiendpointsclasswpresttemplatescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-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="#trunksrcwpincludesrestapiendpointsclasswprestthemescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-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="#trunksrcwpincludesrestapiendpointsclasswprestwidgettypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestwidgetscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestcontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestsearchcontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-search-controller.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswprestapplicationpasswordscontrollerphp"></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-application-passwords-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-application-passwords-controller.php       2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php 2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -610,6 +610,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return $user;
</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">+                $fields = $this->get_fields_for_response( $request );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $prepared = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'uuid'      => $item['uuid'],
</span><span class="cx" style="display: block; padding: 0 10px">                        'app_id'    => empty( $item['app_id'] ) ? '' : $item['app_id'],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -627,8 +629,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $prepared = $this->filter_response_by_context( $prepared, $request['context'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = new WP_REST_Response( $prepared );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->add_links( $this->prepare_links( $user, $item ) );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $user, $item ) );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters the REST API response for an application password.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestblockdirectorycontrollerphp"></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-block-directory-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-block-directory-controller.php     2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php       2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -119,6 +119,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Restores the more descriptive, specific name for use within this method.
</span><span class="cx" style="display: block; padding: 0 10px">                $plugin = $item;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</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">                 // There might be multiple blocks in a plugin. Only the first block is mapped.
</span><span class="cx" style="display: block; padding: 0 10px">                $block_data = reset( $plugin['blocks'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -146,8 +148,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->add_additional_fields_to_object( $block, $request );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = new WP_REST_Response( $block );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->add_links( $this->prepare_links( $plugin ) );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $plugin ) );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $response;
</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="trunksrcwpincludesrestapiendpointsclasswprestblocktypescontrollerphp"></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-block-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-block-types-controller.php 2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php   2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,7 +306,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $block_type ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $block_type ) );
+               }
</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">                 * Filters a block type returned from the REST API.
</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    2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php      2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1119,7 +1119,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $comment ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $comment ) );
+               }
</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">                 * Filters a comment returned from the REST API.
</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     2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php       2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -581,6 +581,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fields = array_keys( $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                /*
+                * '_links' and '_embedded' are not typically part of the item schema,
+                * but they can be specified in '_fields', so they are added here as a
+                * convenience for checking with rest_is_field_included().
+                */
+               $fields[] = '_links';
+               if ( $request->has_param( '_embed' ) ) {
+                       $fields[] = '_embedded';
+               }
+
+               $fields = array_unique( $fields );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! isset( $request['_fields'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return $fields;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestglobalstylescontrollerphp"></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-global-styles-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-global-styles-controller.php       2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php 2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -392,13 +392,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $links = $this->prepare_links( $post->ID );
-               $response->add_links( $links );
-               if ( ! empty( $links['self']['href'] ) ) {
-                       $actions = $this->get_available_actions();
-                       $self    = $links['self']['href'];
-                       foreach ( $actions as $rel ) {
-                               $response->add_link( $rel, $self );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $links = $this->prepare_links( $post->ID );
+                       $response->add_links( $links );
+                       if ( ! empty( $links['self']['href'] ) ) {
+                               $actions = $this->get_available_actions();
+                               $self    = $links['self']['href'];
+                               foreach ( $actions as $rel ) {
+                                       $response->add_link( $rel, $self );
+                               }
</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"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -590,14 +592,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $links = array(
-                       'self' => array(
-                               'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ),
-                       ),
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $links = array(
+                               'self' => array(
+                                       'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ),
+                               ),
+                       );
+                       $response->add_links( $links );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->add_links( $links );
-
</del><span class="cx" style="display: block; padding: 0 10px">                 return $response;
</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="trunksrcwpincludesrestapiendpointsclasswprestmenuitemscontrollerphp"></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-menu-items-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-menu-items-controller.php  2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php    2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -610,16 +610,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $links = $this->prepare_links( $item );
-               $response->add_links( $links );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $links = $this->prepare_links( $item );
+                       $response->add_links( $links );
</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( $links['self']['href'] ) ) {
-                       $actions = $this->get_available_actions( $item, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( ! empty( $links['self']['href'] ) ) {
+                               $actions = $this->get_available_actions( $item, $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">-                        $self = $links['self']['href'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $self = $links['self']['href'];
</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 ( $actions as $rel ) {
-                               $response->add_link( $rel, $self );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         foreach ( $actions as $rel ) {
+                                       $response->add_link( $rel, $self );
+                               }
</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"> 
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestmenulocationscontrollerphp"></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-menu-locations-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-menu-locations-controller.php      2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php        2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -193,7 +193,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $location ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $location ) );
+               }
</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">                 * Filters menu location data returned from the REST API.
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestmenuscontrollerphp"></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-menus-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-menus-controller.php       2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php 2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -134,8 +134,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $data    = $this->filter_response_by_context( $data, $context );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $data );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->add_links( $this->prepare_links( $term ) );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $term ) );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
</span><span class="cx" style="display: block; padding: 0 10px">                return apply_filters( "rest_prepare_{$this->taxonomy}", $response, $term, $request );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpluginscontrollerphp"></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-plugins-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-plugins-controller.php     2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php       2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -576,6 +576,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</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><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">                 $item   = _get_plugin_data_markup_translate( $item['_file'], $item, false );
</span><span class="cx" style="display: block; padding: 0 10px">                $marked = _get_plugin_data_markup_translate( $item['_file'], $item, true );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -600,8 +602,11 @@
</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"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = new WP_REST_Response( $data );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->add_links( $this->prepare_links( $item ) );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $item ) );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters plugin data for a REST API response.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</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  2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php    2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -244,7 +244,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $post_type ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $post_type ) );
+               }
</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">                 * Filters a post type returned from the REST API.
</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       2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1933,16 +1933,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $links = $this->prepare_links( $post );
-               $response->add_links( $links );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $links = $this->prepare_links( $post );
+                       $response->add_links( $links );
</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( $links['self']['href'] ) ) {
-                       $actions = $this->get_available_actions( $post, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( ! empty( $links['self']['href'] ) ) {
+                               $actions = $this->get_available_actions( $post, $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">-                        $self = $links['self']['href'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $self = $links['self']['href'];
</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 ( $actions as $rel ) {
-                               $response->add_link( $rel, $self );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         foreach ( $actions as $rel ) {
+                                       $response->add_link( $rel, $self );
+                               }
</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"> 
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestsearchcontrollerphp"></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-search-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-search-controller.php      2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php        2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,11 +210,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $links               = $handler->prepare_item_links( $item_id );
-               $links['collection'] = array(
-                       'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
-               );
-               $response->add_links( $links );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $links               = $handler->prepare_item_links( $item_id );
+                       $links['collection'] = array(
+                               'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
+                       );
+                       $response->add_links( $links );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $response;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestsidebarscontrollerphp"></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-sidebars-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-sidebars-controller.php    2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php      2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -368,7 +368,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $sidebar ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $sidebar ) );
+               }
</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">                 * Filters the REST API response for a sidebar.
</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  2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php    2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,7 +272,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $taxonomy ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $taxonomy ) );
+               }
</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">                 * Filters a taxonomy returned from the REST API.
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttemplatescontrollerphp"></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-templates-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-templates-controller.php   2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php     2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -662,13 +662,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $links = $this->prepare_links( $template->id );
-               $response->add_links( $links );
-               if ( ! empty( $links['self']['href'] ) ) {
-                       $actions = $this->get_available_actions();
-                       $self    = $links['self']['href'];
-                       foreach ( $actions as $rel ) {
-                               $response->add_link( $rel, $self );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $links = $this->prepare_links( $template->id );
+                       $response->add_links( $links );
+                       if ( ! empty( $links['self']['href'] ) ) {
+                               $actions = $this->get_available_actions();
+                               $self    = $links['self']['href'];
+                               foreach ( $actions as $rel ) {
+                                       $response->add_link( $rel, $self );
+                               }
</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"> 
</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       2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php 2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -859,7 +859,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $item ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $item ) );
+               }
</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">                 * Filters the term data for a REST API response.
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestthemescontrollerphp"></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-themes-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-themes-controller.php      2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php        2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -331,7 +331,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $theme ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $theme ) );
+               }
</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">                 * Filters theme data returned from the REST API.
</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       2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php 2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1072,7 +1072,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Wrap the data in a response object.
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $user ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $user ) );
+               }
</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">                 * Filters user data returned from the REST API.
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestwidgettypescontrollerphp"></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-widget-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-widget-types-controller.php        2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php  2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -335,7 +335,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $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">-                $response->add_links( $this->prepare_links( $widget_type ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $widget_type ) );
+               }
</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">                 * Filters the REST API response for a widget type.
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestwidgetscontrollerphp"></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-widgets-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-widgets-controller.php     2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php       2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -726,7 +726,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $response = rest_ensure_response( $prepared );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response->add_links( $this->prepare_links( $prepared ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+                       $response->add_links( $this->prepare_links( $prepared ) );
+               }
</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">                 * Filters the REST API response for a widget.
</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    2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/tests/phpunit/tests/rest-api/rest-controller.php      2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -386,6 +386,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'somedefault',
</span><span class="cx" style="display: block; padding: 0 10px">                                'somearray',
</span><span class="cx" style="display: block; padding: 0 10px">                                'someobject',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                '_links',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $fields
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -421,11 +422,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'somedefault',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'somearray',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'someobject',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        '_links',
</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">                );
</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_get_fields_for_response_respects_embed() {
+               $controller = new WP_REST_Test_Controller();
+               $request    = new WP_REST_Request( 'GET', '/wp/v2/testroute' );
+
+               $this->assertNotContains( '_embedded', $controller->get_fields_for_response( $request ) );
+
+               $request->set_param( '_embed', 1 );
+
+               $this->assertContains( '_embedded', $controller->get_fields_for_response( $request ) );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_fields_for_response_filters_by_context() {
</span><span class="cx" style="display: block; padding: 0 10px">                $controller = new WP_REST_Test_Controller();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestsearchcontrollerphp"></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-search-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-search-controller.php     2022-07-22 13:22:04 UTC (rev 53759)
+++ trunk/tests/phpunit/tests/rest-api/rest-search-controller.php       2022-07-22 13:58:46 UTC (rev 53760)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -443,7 +443,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'id',
</span><span class="cx" style="display: block; padding: 0 10px">                                'title',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                '_links',
</del><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        array_keys( $data[0] )
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span></span></pre>
</div>
</div>

</body>
</html>