On this page
WP_Site_Icon::insert_attachment( array $attachment, string $file ): int
Inserts an attachment.
Parameters
$attachmentarray Required-
An array with attachment object data.
$filestring Required-
File path of the attached image.
Return
int Attachment ID.
Source
File: wp-admin/includes/class-wp-site-icon.php. View all references
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.
Related
Uses
| Uses | Description |
|---|---|
| wp_generate_attachment_metadata() wp-admin/includes/image.php | Generates attachment meta data and create image sub-sizes for images. |
| wp_insert_attachment() wp-includes/post.php | Inserts an attachment. |
| wp_update_attachment_metadata() wp-includes/post.php | Updates metadata for an attachment. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| wp_ajax_crop_image() wp-admin/includes/ajax-actions.php | Ajax handler for cropping an image. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_site_icon/insert_attachment