Custom_Image_Header::create_attachment_object()

最后更新于:2021-11-25 19:42:52

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

Create an attachment ‘object’.

参数

$cropped

(string) (Required) Cropped image URL.

$parent_attachment_id

(int) (Required) Attachment ID of parent image.

响应

(array) Attachment object.

源文件

文件: gc-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 = gc_get_attachment_url( $parent->ID );
		$url        = str_replace( gc_basename( $parent_url ), gc_basename( $cropped ), $parent_url );

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

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

		return $object;
	}