On this page
Custom_Image_Header::create_attachment_object( string $cropped, int $parent_attachment_id ): array
Create an attachment ‘object’.
Parameters
$croppedstring Required-
Cropped image URL.
$parent_attachment_idint Required-
Attachment ID of parent image.
Return
array An array with attachment object data.
Source
File: wp-admin/includes/class-custom-image-header.php. View all references
final public function create_attachment_object( $cropped, $parent_attachment_id ) {
$parent = get_post( $parent_attachment_id );
$parent_url = wp_get_attachment_url( $parent->ID );
$url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
$size = wp_getimagesize( $cropped );
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
$attachment = array(
'ID' => $parent_attachment_id,
'post_title' => wp_basename( $cropped ),
'post_mime_type' => $image_type,
'guid' => $url,
'context' => 'custom-header',
'post_parent' => $parent_attachment_id,
);
return $attachment;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_getimagesize() wp-includes/media.php | Allows PHP’s getimagesize() to be debuggable when necessary. |
| wp_get_attachment_url() wp-includes/post.php | Retrieves the URL for an attachment. |
| wp_basename() wp-includes/formatting.php | i18n-friendly version of basename(). |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| Custom_Image_Header::ajax_header_crop() wp-admin/includes/class-custom-image-header.php | Gets attachment uploaded by Media Manager, crops it, then saves it as a new object. Returns JSON-encoded object details. |
| Custom_Image_Header::step_3() wp-admin/includes/class-custom-image-header.php | Display third step of custom header image page. |
Changelog
| Version | Description |
|---|---|
| 3.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/custom_image_header/create_attachment_object