| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * REST API: WP_REST_Revision_Meta_Fields class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 7.2.0 8 */ 9 10 /** 11 * Core class used to read the meta values of post revisions via the REST API. 12 * 13 * Only the meta keys that are revisioned for the parent post type are exposed, 14 * because those are the only values that are stored on a revision. Any other 15 * meta key registered for the post type would be read from the revision ID, 16 * find nothing, and be reported with its default value instead. 17 * 18 * @since 7.2.0 19 * 20 * @see WP_REST_Post_Meta_Fields 21 * @see wp_post_revision_meta_keys() 22 */ 23 class WP_REST_Revision_Meta_Fields extends WP_REST_Post_Meta_Fields { 24 25 /** 26 * Retrieves the meta field values for a revision. 27 * 28 * When an author autosaves their own draft, the autosaves controller updates 29 * the post itself and returns it instead of an autosave. That post stores all 30 * of its meta, so its values are read as regular post meta. 31 * 32 * @since 7.2.0 33 * 34 * @param int $object_id Object ID to fetch meta for. 35 * @param WP_REST_Request $request Full details about the request. 36 * @return array Array containing the meta values keyed by name. 37 */ 38 public function get_value( $object_id, $request ) { 39 if ( 'revision' !== get_post_type( $object_id ) ) { 40 $post_meta = new WP_REST_Post_Meta_Fields( $this->post_type ); 41 return $post_meta->get_value( $object_id, $request ); 42 } 43 44 return parent::get_value( $object_id, $request ); 45 } 46 47 /** 48 * Retrieves the registered meta fields that are revisioned for the parent post type. 49 * 50 * @since 7.2.0 51 * 52 * @return array Registered fields, limited to the revisioned meta keys. 53 */ 54 protected function get_registered_fields() { 55 // The keys are filterable, so ignore anything that isn't a meta key. 56 $revisioned_keys = array_filter( (array) wp_post_revision_meta_keys( $this->post_type ), 'is_string' ); 57 58 return array_intersect_key( 59 parent::get_registered_fields(), 60 array_flip( $revisioned_keys ) 61 ); 62 } 63 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Tue Oct 27 08:20:35 2026 | Cross-referenced by PHPXref |