WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 months ago

#12238 new enhancement

image helper functions that I think would be useful in the core — at Initial Version

Reported by: jredfern Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch dev-feedback
Focuses: Cc:

Description

It's useful to get all the data relating to an image via one source:

/

  • returns an array containing attributes for an image stored in the database
    • $image_id : id of the image to query
    • $size : size of the image, can be 'thumbnail', 'medium', 'large' or 'full' */

function get_image_by_id($image_id, $size) {

$image = get_post($image_id);

$imageObj = array();
$imagearray = wp_get_attachment_image_src($image->ID, $size, false);
$imageObjsrc? = $imagearray[0];
$imageObjwidth? = $imagearray[1];
$imageObjheight? = $imagearray[2];
$imageObjid? = $image->ID;
$imageObjtitle? = $image->post_title;
$imageObjcaption? = $image->post_excerpt;
$imageObjdescription? = $image->post_content;
$imageObjalt? = get_post_meta($image->ID, '_wp_attachment_image_alt', true);

return $imageObj;

}

Change History (0)

Note: See TracTickets for help on using tickets.