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/custom-header.php

	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;
	}


Changelog

Changelog
Version Description
WP-3.9.0 Introduced.