Custom_Image_Header::create_attachment_objectpublicWP 3.9.0

Deprecated since 6.5.0. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Creates an attachment 'object'.

Method of the class: Custom_Image_Header{}

No Hooks.

Returns

Array. An array with attachment object data.

Usage

$Custom_Image_Header = new Custom_Image_Header();
$Custom_Image_Header->create_attachment_object( $cropped, $parent_attachment_id );
$cropped(string) (required)
Cropped image URL.
$parent_attachment_id(int) (required)
Attachment ID of parent image.

Changelog

Since 3.9.0 Introduced.
Deprecated since 6.5.0

Custom_Image_Header::create_attachment_object() code WP 6.9

final public function create_attachment_object( $cropped, $parent_attachment_id ) {
	_deprecated_function( __METHOD__, '6.5.0', 'wp_copy_parent_attachment_properties()' );
	$parent     = get_post( $parent_attachment_id );
	$parent_url = wp_get_attachment_url( $parent->ID );
	$url        = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );

	$size       = wp_getimagesize( $cropped );
	$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';

	$attachment = array(
		'ID'             => $parent_attachment_id,
		'post_title'     => wp_basename( $cropped ),
		'post_mime_type' => $image_type,
		'guid'           => $url,
		'context'        => 'custom-header',
		'post_parent'    => $parent_attachment_id,
	);

	return $attachment;
}