• Resolved Azragh

    (@azragh)


    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): string

    However, WordPress seems to pass an array in this Customizer context when calling get_theme_mod('header_image', Array). Since the theme_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): string

    A 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!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Ryan Hellyer

    (@ryanhellyer)

    I didn’t even realise videos even worked in the plugin! It’s for header images. Video support would have been a side effect of how it works, rather something intentional.

    But since it worked before, I will get to work and make it work with videos again for you. I’ll post back here once I have a test version ready for you to try.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    I misunderstood originally. You are trying to add videos via the customizer, not this plugin, but you are getting errors because of this plugin. That is a definite bug if it is the case. I’m working on it right now. I’ll try to fix out as soon as possible.

    Thanks for alerting me to this problem. It didn’t show up during the testing process.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    I’m having some trouble replicating this bug. Do you have any extra info. that may be relevant, or which could help me replicate the problem? Thanks 🙂

    In the mean time, I’ll clean up a test version I have and provide it for you here to test with in case it helps. I tried your ideas about loosening the type requirements up a bit. I’ll post it here once it’s ready.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Could you try this version of the plugin to see if it fixes your problem?
    https://stuff.hellyer.kiwi/temp/unique-headers-2.1.2.zip

    It has no affect on my test setup. I can upload videos to the header just fine on it, and they don’t interfere with how the plugin works, so I’m not able to debug this myself sorry. If we’re lucky, it will do the trick. If it works, I’ll release it as the official version.

    I had the same problem. I’m using WooCommerce with the Orchid Store theme, and with the latest update, the header images stopped displaying, and when I tried to access the Customizer, I got a fatal error. I tried the version you uploaded in the previous post, and I was able to access the Customizer without errors, but I lost the ability to apply a custom header to a product category.

    Sorry for my English; I’m using a translator.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    @gnukleo  Thank you! I’m able to replicate your problem. I’m working on a solution right now for you.

    • This reply was modified 12 hours, 42 minutes ago by Ryan Hellyer.
    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Thanks for the extra context. It was impossible for me to fix this, as I couldn’t find a problem until your comment here.

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    I figured out the problem. The taxonomies are collected all in one go on loading the plugin, but WooCommerce loads it’s later on, which causes it not allow for custom headers. This didn’t matter with other categories, because they’re set earlier in the load cycle.

    I’ll have a solution to this ready soon …

    Plugin Author Ryan Hellyer

    (@ryanhellyer)

    Version 2.1.3 is now published. Hopefully that fixes the problem for you, if not, let me know.

    I’m setting this topic as “resolved”, but I can’t set it as “unresolved” if you experience any problems.

    Perfect, everything is working again. Thank you so much.

    As a suggestion for future versions, you could add the option for subcategories to use the header of the main category (unless a specific header is selected for that subcategory). This would maintain a consistent look when navigating through the subcategories.
    Anyway, it’s just a small detail to avoid configuring each one individually.

    Thanks again for your work.

Viewing 10 replies - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.