Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-customize-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5410,7 +5410,7 @@ public function register_controls() {
$this,
'header_image',
array(
'default' => sprintf( get_theme_support( 'custom-header', 'default-image' ), get_template_directory_uri(), get_stylesheet_directory_uri() ),
'default' => current_theme_supports( 'custom-header', 'random-default' ) ? 'random-default-image' : sprintf( get_theme_support( 'custom-header', 'default-image' ), get_template_directory_uri(), get_stylesheet_directory_uri() ),
'theme_supports' => 'custom-header',
)
)
Expand Down
43 changes: 43 additions & 0 deletions tests/phpunit/tests/customize/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3683,6 +3683,49 @@ public function test_sanitize_external_header_video_trim() {
$this->assertSame( $video_url, $sanitized );
}
}

/**
* @ticket 46128
*
* @dataProvider data_header_image_setting_default
*
* @param bool $random_default Whether to randomize default headers.
* @param string $expected_default Expected setting default.
*/
public function test_header_image_setting_default( $random_default, $expected_default ) {
global $_wp_theme_features;

$custom_header_support = isset( $_wp_theme_features['custom-header'] ) ? $_wp_theme_features['custom-header'] : null;

try {
$_wp_theme_features['custom-header'][0] = array(
'default-image' => 'https://example.org/header.jpg',
'random-default' => $random_default,
);

$this->manager->register_controls();

$this->assertSame( $expected_default, $this->manager->get_setting( 'header_image' )->default );
} finally {
if ( null === $custom_header_support ) {
unset( $_wp_theme_features['custom-header'] );
} else {
$_wp_theme_features['custom-header'] = $custom_header_support;
}
}
}

/**
* Data provider for test_header_image_setting_default().
*
* @return array[] Test parameters.
*/
public function data_header_image_setting_default() {
return array(
'random default headers' => array( true, 'random-default-image' ),
'fixed default header' => array( false, 'https://example.org/header.jpg' ),
);
}
}

require_once ABSPATH . WPINC . '/class-wp-customize-setting.php';
Expand Down
Loading