Custom_Image_Header::insert_attachment()

最后更新于:2021-11-25 19:45:54

Custom_Image_Header::insert_attachment( array$object, string$cropped)

Insert an attachment and its metadata.

参数

$object

(array) (Required) Attachment object.

$cropped

(string) (Required) File path to cropped image.

响应

(int) Attachment ID.

源文件

文件: gc-admin/includes/class-custom-image-header.php

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

		$attachment_id = gc_insert_attachment( $object, $cropped );
		$metadata      = gc_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 gc_generate_attachment_metadata()
		 *
		 * @param array $metadata Attachment metadata.
		 */
		$metadata = apply_filters( 'gc_header_image_attachment_metadata', $metadata );

		gc_update_attachment_metadata( $attachment_id, $metadata );

		return $attachment_id;
	}