W3cubDocs

/WordPress

WP_REST_Posts_Controller::handle_featured_media( int $featured_media, int $post_id )

Determines the featured media based on a request param.

Parameters

$featured_media

(int) (Required) Featured Media ID.

$post_id

(int) (Required) Post ID.

Return

(bool|WP_Error) Whether the post thumbnail was successfully deleted, otherwise WP_Error.

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.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 );
		}

	}

Changelog

Version Description
4.7.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/handle_featured_media