true ) ) as $type ) { register_rest_field( $type, self::FIELD, array( 'get_callback' => array( self::class, 'sync_status' ), 'schema' => array( 'description' => __( 'show.fm sync status for this post.', 'showfm' ), 'type' => array( 'object', 'null' ), 'context' => array( 'edit' ), 'readonly' => true, ), ) ); } } /** * The post's sync status from WP-4a's post meta, for people who can edit it. * * @param array $post Prepared post data. * @return array|null */ public static function sync_status( array $post ): ?array { $id = (int) ( $post['id'] ?? 0 ); if ( ! $id || ! current_user_can( 'edit_post', $id ) ) { return null; } $state = (string) get_post_meta( $id, '_showfm_sync_state', true ); $synced = (int) get_post_meta( $id, '_showfm_synced_at', true ); return array( 'synced' => '' !== (string) get_post_meta( $id, '_showfm_site_id', true ), 'state' => preg_match( '/\A[a-z_]{1,32}\z/', $state ) ? $state : '', 'edited' => (bool) get_post_meta( $id, '_showfm_edited', true ), 'syncedAt' => $synced > 0 ? gmdate( 'c', $synced ) : null, ); } }