WordPress at a glance
function is not described

WP_REST_Posts_Controller::handle_featured_media() protected WP 4.7.0

Determines the featured media based on a request param.

{} It's a method of the class: WP_REST_Posts_Controller{}

No Hooks.

Return

true/false/WP_Error. Whether the post thumbnail was successfully deleted, otherwise WP_Error.

Usage

// protected - for code of main (parent) or child class
$result = $this->handle_featured_media( $featured_media, $post_id );
$featured_media(int) (required)
Featured Media ID.
$post_id(int) (required)
Post ID.

Changelog

Since 4.7.0 Introduced.

Code of WP_REST_Posts_Controller::handle_featured_media() WP 5.5.2

<?php
protected function handle_featured_media( $featured_media, $post_id ) {

	$featured_media = (int) $featured_media;
	if ( $featured_media ) {
		$result = set_post_thumbnail( $post_id, $featured_media );
		if ( $result ) {
			return true;
		} else {
			return new WP_Error(
				'rest_invalid_featured_media',
				__( 'Invalid featured media ID.' ),
				array( 'status' => 400 )
			);
		}
	} else {
		return delete_post_thumbnail( $post_id );
	}

}