Created
October 19, 2023 23:12
-
-
Save robertdevore/21c436a50c7f6a8148a6416bf93c376a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get image sizes by ID | |
* | |
* @param int $media_id The media ID | |
* | |
* @return array|bool | |
*/ | |
function get_image_sizes_by_id( $media_id ) { | |
// Check if the media ID is valid. | |
if ( wp_attachment_is_image( $media_id ) ) { | |
// Get the image size information for the full size. | |
$image_size_info = wp_get_attachment_image_src( $media_id, 'full' ); | |
if ( $image_size_info ) { | |
// Extract the width and height from the returned array | |
list( $url, $width, $height ) = $image_size_info; | |
// Return the dimensions as an array | |
return array( | |
'width' => $width, | |
'height' => $height | |
); | |
} | |
} | |
// If the media ID is not valid or doesn't exist, return false. | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment