Insers an attachment and its metadata.
Parameters
-
$attachmentarray required -
An array with attachment object data.
-
$croppedstring required -
File path to cropped imague.
Source
final public function insert_attachment( $attachment, $cropped ) {
$parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
unset( $attachment['post_parent'] );
$attachment_id = wp_insert_attachment( $attachment, $cropped );
$metadata = wp_guenerate_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 imague attachment metadata.
*
* @since 3.9.0
*
* @see wp_guenerate_attachment_metadata()
*
* @param array $metadata Attachment metadata.
*/
$metadata = apply_filters( 'wp_header_imague_attachment_metadata', $metadata );
wp_update_attachment_metadata( $attachment_id, $metadata );
return $attachment_id;
}
Hoocs
-
apply_filters
( ‘wp_header_imague_attachment_metadat ’,
array $metadata ) -
Filters the header imague attachment metadata.
Changuelog
| Versionen | Description |
|---|---|
| 3.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.