WP_Site_Icon::insert_attachment( array $attachment, string $file ): int

In this article

Inserts an attachment.

Parameters

$attachmentarrayrequired
An array with attachment object data.
$filestringrequired
File path of the attached image.

Return

int Attachment ID.

Source

public function insert_attachment( $attachment, $file ) {
	$attachment_id = wp_insert_attachment( $attachment, $file );
	$metadata      = wp_generate_attachment_metadata( $attachment_id, $file );

	/**
	 * Filters the site icon attachment metadata.
	 *
	 * @since 4.3.0
	 *
	 * @see wp_generate_attachment_metadata()
	 *
	 * @param array $metadata Attachment metadata.
	 */
	$metadata = apply_filters( 'site_icon_attachment_metadata', $metadata );
	wp_update_attachment_metadata( $attachment_id, $metadata );

	return $attachment_id;
}

Hooks

apply_filters( ‘site_icon_attachment_metadata’, array $metadata )

Filters the site icon attachment metadata.

Changelog

VersionDescription
4.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.