Last active
November 18, 2018 20:28
-
-
Save DevWael/3d282de8879e3bf35d5f426d87647f92 to your computer and use it in GitHub Desktop.
Return all images sizes register by add_image_size() merged with WordPress default image sizes.
This file contains hidden or 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 | |
| /** | |
| * Return all images sizes register by add_image_size() merged with | |
| * WordPress default image sizes. | |
| * @link https://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes | |
| * | |
| * @param string $size | |
| * | |
| * @return array|bool | |
| */ | |
| 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