WP_REST_Attachments_Controller::handle_featured_media
Determines the featured media based on a request param.
Метод класса: WP_REST_Attachments_Controller{}
Хуков нет.
Возвращает
true|false|WP_Error. Whether the post thumbnail was successfully deleted, otherwise WP_Error.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->handle_featured_media( $featured_media, $post_id );
- $featured_media(int) (обязательный)
- Featured Media ID.
- $post_id(int) (обязательный)
- Post ID.
Список изменений
| С версии 6.5.0 | Введена. |
Код WP_REST_Attachments_Controller::handle_featured_media() WP REST Attachments Controller::handle featured media WP 7.0
protected function handle_featured_media( $featured_media, $post_id ) {
$post_type = get_post_type( $post_id );
$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
// Similar check as in wp_insert_post().
if ( ! $thumbnail_support && get_post_mime_type( $post_id ) ) {
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 ) {
return parent::handle_featured_media( $featured_media, $post_id );
}
return new WP_Error(
'rest_no_featured_media',
sprintf(
/* translators: %s: attachment mime type */
__( 'This site does not support post thumbnails on attachments with MIME type %s.' ),
get_post_mime_type( $post_id )
),
array( 'status' => 400 )
);
}