@@ -639,35 +639,46 @@ public function prepare_item_for_response( $item, $request ) {
639639 $ data ['slug ' ] = $ post ->post_name ;
640640 }
641641
642- if ( in_array ( 'guid ' , $ fields , true ) ) {
643- $ data ['guid ' ] = array (
644- /** This filter is documented in wp-includes/post-template.php */
645- 'rendered ' => apply_filters ( 'get_the_guid ' , $ post ->guid , $ post ->ID ),
646- 'raw ' => $ post ->guid ,
647- );
642+ if ( rest_is_field_included ( 'guid ' , $ fields ) ) {
643+ $ data ['guid ' ] = array ();
648644 }
649-
650- if ( in_array ( ' title ' , $ fields , true ) ) {
651- $ data ['title ' ] = array (
652- ' raw ' => $ post -> post_title ,
653- ' rendered ' => get_the_title ( $ post -> ID ),
654- ) ;
645+ if ( rest_is_field_included ( ' guid.rendered ' , $ fields ) ) {
646+ /** This filter is documented in wp-includes/post-template.php */
647+ $ data ['guid ' ][ ' rendered ' ] = apply_filters ( ' get_the_guid ' , $ post -> guid , $ post -> ID );
648+ }
649+ if ( rest_is_field_included ( ' guid.raw ' , $ fields ) ) {
650+ $ data [ ' guid ' ][ ' raw ' ] = $ post -> guid ;
655651 }
656652
657- if ( in_array ( 'content ' , $ fields , true ) ) {
653+ if ( rest_is_field_included ( 'title ' , $ fields ) ) {
654+ $ data ['title ' ] = array ();
655+ }
656+ if ( rest_is_field_included ( 'title.raw ' , $ fields ) ) {
657+ $ data ['title ' ]['raw ' ] = $ post ->post_title ;
658+ }
659+ if ( rest_is_field_included ( 'title.rendered ' , $ fields ) ) {
660+ $ data ['title ' ]['rendered ' ] = get_the_title ( $ post ->ID );
661+ }
658662
659- $ data ['content ' ] = array (
660- 'raw ' => $ post ->post_content ,
661- /** This filter is documented in wp-includes/post-template.php */
662- 'rendered ' => apply_filters ( 'the_content ' , $ post ->post_content ),
663- );
663+ if ( rest_is_field_included ( 'content ' , $ fields ) ) {
664+ $ data ['content ' ] = array ();
665+ }
666+ if ( rest_is_field_included ( 'content.raw ' , $ fields ) ) {
667+ $ data ['content ' ]['raw ' ] = $ post ->post_content ;
668+ }
669+ if ( rest_is_field_included ( 'content.rendered ' , $ fields ) ) {
670+ /** This filter is documented in wp-includes/post-template.php */
671+ $ data ['content ' ]['rendered ' ] = apply_filters ( 'the_content ' , $ post ->post_content );
664672 }
665673
666- if ( in_array ( 'excerpt ' , $ fields , true ) ) {
667- $ data ['excerpt ' ] = array (
668- 'raw ' => $ post ->post_excerpt ,
669- 'rendered ' => $ this ->prepare_excerpt_response ( $ post ->post_excerpt , $ post ),
670- );
674+ if ( rest_is_field_included ( 'excerpt ' , $ fields ) ) {
675+ $ data ['excerpt ' ] = array ();
676+ }
677+ if ( rest_is_field_included ( 'excerpt.raw ' , $ fields ) ) {
678+ $ data ['excerpt ' ]['raw ' ] = $ post ->post_excerpt ;
679+ }
680+ if ( rest_is_field_included ( 'excerpt.rendered ' , $ fields ) ) {
681+ $ data ['excerpt ' ]['rendered ' ] = $ this ->prepare_excerpt_response ( $ post ->post_excerpt , $ post );
671682 }
672683
673684 if ( rest_is_field_included ( 'meta ' , $ fields ) ) {
0 commit comments