if ( !
empty( $postarr['context'
] ) ) { add_post_meta( $post_id, '_wp_attachment_context',
$postarr['context'
], true
);
} } // Set or remove featured image.
if ( isset( $postarr['_thumbnail_id'
] ) ) { $thumbnail_support =
current_theme_supports( 'post-thumbnails',
$post_type ) &&
post_type_supports( $post_type, 'thumbnail'
) || 'revision' ===
$post_type;
if ( !
$thumbnail_support && 'attachment' ===
$post_type &&
$post_mime_type ) { if ( wp_attachment_is( 'audio',
$post_id ) ) { $thumbnail_support =
post_type_supports( 'attachment:audio', 'thumbnail'
) ||
current_theme_supports( 'post-thumbnails', 'attachment:audio'
);
} elseif ( wp_attachment_is( 'video',
$post_id ) ) { $thumbnail_support =
post_type_supports( 'attachment:video', 'thumbnail'
) ||
current_theme_supports( 'post-thumbnails', 'attachment:video'
);
} } if ( $thumbnail_support ) { $thumbnail_id =
(int) $postarr['_thumbnail_id'
];
if ( -1 ===
$thumbnail_id ) { delete_post_thumbnail( $post_id );
} else {