WordPress at Your Fingertips
function is not described

WP_Site_Icon::create_attachment_object() public WP 4.3.0

Creates an attachment 'object'.

{} It's a method of the class: WP_Site_Icon{}

No Hooks.

Return

Array. Attachment object.

Usage

$WP_Site_Icon = new WP_Site_Icon();
$WP_Site_Icon->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 4.3.0 Introduced.

Code of WP_Site_Icon::create_attachment_object() WP 5.8.2

public function create_attachment_object( $cropped, $parent_attachment_id ) {
	$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';

	$object = array(
		'ID'             => $parent_attachment_id,
		'post_title'     => wp_basename( $cropped ),
		'post_content'   => $url,
		'post_mime_type' => $image_type,
		'guid'           => $url,
		'context'        => 'site-icon',
	);

	return $object;
}