WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Custom_Image_Header::insert_attachment() public WP 3.9.0

Insert an attachment and its metadata.

Это метод класса: Custom_Image_Header{}

Хуки из метода
Возвращает

Число. Attachment ID.

Использование

$Custom_Image_Header = new Custom_Image_Header();
$Custom_Image_Header->insert_attachment( $object, $cropped );
$object(массив) (обязательный)
Attachment object.
$cropped(строка) (обязательный)
File path to cropped image.

Список изменений

С версии 3.9.0 Введена.

Код Custom Image Header::insert attachment: wp-admin/includes/class-custom-image-header.php WP 5.5.1

<?php
final public function insert_attachment( $object, $cropped ) {
	$parent_id = isset( $object['post_parent'] ) ? $object['post_parent'] : null;
	unset( $object['post_parent'] );

	$attachment_id = wp_insert_attachment( $object, $cropped );
	$metadata      = wp_generate_attachment_metadata( $attachment_id, $cropped );

	// If this is a crop, save the original attachment ID as metadata.
	if ( $parent_id ) {
		$metadata['attachment_parent'] = $parent_id;
	}

	/**
	 * Filters the header image attachment metadata.
	 *
	 * @since 3.9.0
	 *
	 * @see wp_generate_attachment_metadata()
	 *
	 * @param array $metadata Attachment metadata.
	 */
	$metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );

	wp_update_attachment_metadata( $attachment_id, $metadata );

	return $attachment_id;
}