[wp-trac] [WordPress Trac] #54484: REST API returns (empty) array for Meta but Schema has type object

WordPress Trac noreply at wordpress.org
Wed Apr 29 10:25:51 UTC 2026


#54484: REST API returns (empty) array for Meta but Schema has type object
-----------------------------------------+-----------------------
 Reporter:  dtrunk90                     |       Owner:  flixos90
     Type:  defect (bug)                 |      Status:  assigned
 Priority:  normal                       |   Milestone:  7.1
Component:  REST API                     |     Version:  4.7
 Severity:  normal                       |  Resolution:
 Keywords:  has-patch changes-requested  |     Focuses:
-----------------------------------------+-----------------------

Comment (by liaison):

 I’ve refactored the patch to use a more concise approach by casting
 $data['meta'] to an array for value extraction. This eliminates the
 redundant if/elseif blocks while safely handling both object and array
 structures.

 Improvements:

 Reduced Complexity: Replaced explicit structure checks with the null
 coalescing operator (??) for cleaner logic.

 Unified Extraction: By temporarily casting meta to an array, we extract
 wp_pattern_sync_status in a single line regardless of the input type.

 Code Density: Combined unset() calls and removed unnecessary branching,
 making the function more maintainable without changing the functional
 outcome.
 {{{#!php
 <?php
 public function filter_response_by_context( $data, $context ) {
     unset( $data['title']['rendered'], $data['content']['rendered'] );

     $meta = (array) $data['meta'];
     $data['wp_pattern_sync_status'] = $meta['wp_pattern_sync_status'] ??
 '';

      if ( is_object( $data['meta'] ) ) {
         unset( $data['meta']->wp_pattern_sync_status );
     } else {
         unset( $data['meta']['wp_pattern_sync_status'] );
     }

     return $data;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54484#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list