[wp-trac] [WordPress Trac] #44748: Ability to register custom embeds to built-in endpoints

WordPress Trac noreply at wordpress.org
Tue Aug 7 10:28:11 UTC 2018


#44748: Ability to register custom embeds to built-in endpoints
-----------------------------+------------------------------
 Reporter:  k1sul1           |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  REST API         |     Version:
 Severity:  normal           |  Resolution:
 Keywords:  needs-patch      |     Focuses:
-----------------------------+------------------------------

Comment (by k1sul1):

 This is one way of doing it at the moment but it doesn't feel right.

 {{{
 register_rest_field('post', 'linkedProductCards', [
   'get_callback' => function($post, $field_name, $request) {
     $params = $request->get_params();

     if (empty($params['_embed']) || $params['_embed'] === '0') {
       return [];
     }

     $linked = get_field('linkedProductCards', $post['id']);

     if (!$linked) {
       $linked = [];
     }

     return array_map(function($id) {
       return \NS\REST\get_post_from_api($id);
     }, $linked);
   },
   'schema' => [
     'description' => 'Array of posts, in REST API format',
     'type'        => 'array'
   ],
 ]);

 }}}

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


More information about the wp-trac mailing list