array( $this, 'get_featured_media_url' ), 'update_callback' => null, 'schema' => null, ) ); } /** * Get featured media url. * * @param mixed $object What the endpoint returns. * @param string $field_name Should always match `->field_name`. * @param WP_REST_Request $request WP API request. * * @return string */ public function get_featured_media_url( $object, $field_name, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable if ( ! isset( $object['id'] ) ) { return ''; } $featured_media_url = ''; $image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $object['id'] ), 'full' ); if ( is_array( $image_attributes ) && isset( $image_attributes[0] ) ) { $featured_media_url = (string) $image_attributes[0]; } return $featured_media_url; } } wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Sites_Posts_Add_Featured_Media_URL' );