Custom_Image_Header::create_attachment_object

Advertisement

Summery Summery

Create an attachment ‘object’.

Syntax Syntax

Custom_Image_Header::create_attachment_object( string $cropped, int $parent_attachment_id )

Parameters Parameters

$cropped

(Required) Cropped image URL.

$parent_attachment_id

(Required) Attachment ID of parent image.

Return Return

(array) Attachment object.

Source Source

File: wp-admin/includes/class-custom-image-header.php

	final 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       = @getimagesize( $cropped );
		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';

		$object = 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 $object;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
3.9.0 Introduced.

Advertisement

Leave a Reply