Created
December 12, 2018 10:33
-
-
Save dannyconnolly/a9d5840220cbcb821504c9108575a9e6 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
/** | |
* Get information about available image sizes | |
*/ | |
function get_image_sizes($size = '') | |
{ | |
global $_wp_additional_image_sizes; | |
$sizes = array(); | |
$get_intermediate_image_sizes = get_intermediate_image_sizes(); | |
// Create the full array with sizes and crop info | |
foreach ($get_intermediate_image_sizes as $_size) { | |
if (in_array($_size, array('thumbnail', 'medium', 'large'))) { | |
$sizes[$_size]['width'] = get_option($_size . '_size_w'); | |
$sizes[$_size]['height'] = get_option($_size . '_size_h'); | |
$sizes[$_size]['crop'] = (bool) get_option($_size . '_crop'); | |
} | |
elseif (isset($_wp_additional_image_sizes[$_size])) { | |
$sizes[$_size] = array( | |
'width' => $_wp_additional_image_sizes[$_size]['width'], | |
'height' => $_wp_additional_image_sizes[$_size]['height'], | |
'crop' => $_wp_additional_image_sizes[$_size]['crop'] | |
); | |
} | |
} | |
// Get only 1 size if found | |
if ($size) { | |
if (isset($sizes[$size])) { | |
return $sizes[$size]; | |
} | |
else { | |
return false; | |
} | |
} | |
return $sizes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment