Custom_Image_Header::get_header_dimensions() WordPress Method
The Custom_Image_Header::get_header_dimensions() method is used to get the width and height of the custom image header. This information is used to set the width and height of the image tag on the front-end.
Custom_Image_Header::get_header_dimensions( array $dimensions ) #
Calculate width and height based on what the currently selected theme supports.
Parameters
- $dimensions
(array)(Required)
Return
(array) dst_height and dst_width of header image.
Source
File: wp-admin/includes/class-custom-image-header.php
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 | final public function get_header_dimensions( $dimensions ) { $max_width = 0; $width = absint( $dimensions [ 'width' ] ); $height = absint( $dimensions [ 'height' ] ); $theme_height = get_theme_support( 'custom-header' , 'height' ); $theme_width = get_theme_support( 'custom-header' , 'width' ); $has_flex_width = current_theme_supports( 'custom-header' , 'flex-width' ); $has_flex_height = current_theme_supports( 'custom-header' , 'flex-height' ); $has_max_width = current_theme_supports( 'custom-header' , 'max-width' ); $dst = array ( 'dst_height' => null, 'dst_width' => null, ); // For flex, limit size of image displayed to 1500px unless theme says otherwise. if ( $has_flex_width ) { $max_width = 1500; } if ( $has_max_width ) { $max_width = max( $max_width , get_theme_support( 'custom-header' , 'max-width' ) ); } $max_width = max( $max_width , $theme_width ); if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) { $dst [ 'dst_height' ] = absint( $height * ( $max_width / $width ) ); } elseif ( $has_flex_height && $has_flex_width ) { $dst [ 'dst_height' ] = $height ; } else { $dst [ 'dst_height' ] = $theme_height ; } if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) { $dst [ 'dst_width' ] = absint( $width * ( $max_width / $width ) ); } elseif ( $has_flex_width && $has_flex_height ) { $dst [ 'dst_width' ] = $width ; } else { $dst [ 'dst_width' ] = $theme_width ; } return $dst ; } |
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.9.0 | Introduced. |