Fatal error in Customizer: theme_mod_header_image filter receives array
-
Hi,
I ran into a fatal error when trying to add a header video via the WordPress Customizer. Setting individual images on pages works, but when I try to open the Customizer to add a Video the error occurs.
The theme uses the native WordPress Custom Header feature with video support:
add_theme_support( 'custom-header', array(
'default-image' => '',
'width' => 1920,
'height' => 1080,
'flex-height' => false,
'video' => true,
) );and outputs it via:
the_custom_header_markup();When opening the Customizer / trying to set a header video, the following fatal error occurs:
Fatal error: Uncaught TypeError: RyanHellyer\UniqueHeaders\DisplayModule::taxonomyHeaderImageFilter(): Argument #1 ($url) must be of type string, array given, called in wp-includes/class-wp-hook.php on line 341 and defined in wp-content/plugins/unique-headers/src/DisplayModule.php:77
Stack trace excerpt:
0 wp-includes/class-wp-hook.php(341): RyanHellyer\UniqueHeaders\DisplayModule->taxonomyHeaderImageFilter(Array)
1 wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
2 wp-includes/theme.php(1095): apply_filters('theme_mod_heade…', Array)
3 wp-includes/class-wp-customize-setting.php(638): get_theme_mod('header_image', Array)
4 wp-includes/class-wp-customize-setting.php(258): WP_Customize_Setting->get_root_value(Array)
5 wp-includes/class-wp-customize-setting.php(216): WP_Customize_Setting->aggregate_multidimensional()
6 wp-includes/class-wp-customize-manager.php(5408): WP_Customize_Setting->__construct(Object(WP_Customize_Manager), 'header_image', Array)It looks like the plugin callback attached to theme_mod_header_image is too strictly typed:
public function taxonomyHeaderImageFilter(string $url): stringHowever, WordPress seems to pass an array in this Customizer context when calling
get_theme_mod('header_image', Array). Since thetheme_mod_{$name}filter can receive mixed values, this causes a fatal TypeError before the Customizer can load.The same may also apply to:
public function postHeaderImageFilter(string $url): stringA possible fix would be to remove the strict string type declaration and return non-string values unchanged, for example:
public function taxonomyHeaderImageFilter($url) {
if (! is_string($url)) {
return $url;
}
// existing logic...
}Same for
postHeaderImageFilter().This started happening after the recent plugin update. The theme itself does not modify the value before the Unique Headers filter runs; the plugin filter runs earlier and crashes as soon as WordPress passes the array value.
Could you please check this?
Thanks!
You must be logged in to reply to this topic.