wp-content/plugins/better-rest-api-featured-images/better-rest-api-featured-images.php
/**
 * Register our enhanced better_featured_image field to all public post types
 * that support post thumbnails.
 *
 * @since  1.0.0
 */
Register our enhanced better_featured_image field to all public post types
that support post thumbnails.


Register our enhanced better_featured_image field to all public post types that support post thumbnails .
function better_rest_api_featured_images_init() {
	$post_types = get_post_types( array( 'public' => true ), 'objects' );
	foreach ( $post_types as $post_type ) {
		$post_type_name     = $post_type->name;
		$show_in_rest       = ( isset( $post_type->show_in_rest ) && $post_type->show_in_rest ) ? true : false;
		$supports_thumbnail = post_type_supports( $post_type_name, 'thumbnail' );
		if ( $show_in_rest && $supports_thumbnail ) {
			if ( function_exists( 'register_rest_field' ) ) {
				register_rest_field( $post_type_name,
					'better_featured_image',
					array(
						'get_callback' => 'better_rest_api_featured_images_get_field',
						'schema'       => null,
					)
				);
			} elseif ( function_exists( 'register_api_field' ) ) {
				register_api_field( $post_type_name,
					'better_featured_image',
					array(
						'get_callback' => 'better_rest_api_featured_images_get_field',
						'schema'       => null,
					)
				);
			}
		}
	}
}
function better_rest_api_featured_images_init ( ) { $ post_types = get_post_types ( array ( 'public' => true ) , 'objects' ) ; foreach ( $ post_types as $ post_type ) { $ post_type_name = $ post_type -> name ; $ show_in_rest = ( isset ( $ post_type -> show_in_rest ) && $ post_type -> show_in_rest ) ? true : false ; $ supports_thumbnail = post_type_supports ( $ post_type_name , 'thumbnail' ) ; if ( $ show_in_rest && $ supports_thumbnail ) { if ( function_exists ( 'register_rest_field' ) ) { register_rest_field ( $ post_type_name , 'better_featured_image' , array ( 'get_callback' => 'better_rest_api_featured_images_get_field' , 'schema' => null , ) ) ; } elseif ( function_exists ( 'register_api_field' ) ) { register_api_field ( $ post_type_name , 'better_featured_image' , array ( 'get_callback' => 'better_rest_api_featured_images_get_field' , 'schema' => null , ) ) ; } } } }
Register our enhanced better_featured_image field to all public post types
 that support post thumbnails.
Register our enhanced better_featured_image field to all public post types that support post thumbnails .
// Only proceed if the post type is set to be accessible over the REST API // and supports featured images. // Compatibility with the REST API v2 beta 9+