Skip to content

PHP 8.1 deprecation: false to array conversion in build_logo_meta #2807

@curtismchale

Description

@curtismchale

Builds

Bug

PHP 8.1 deprecation notice on every page load when a site logo attachment has no registered image metadata:

Deprecated: Automatic conversion of false to array is deprecated in
wp-content/plugins/wp-proud-core/modules/proud-navbar/proud-navbar.php on line 123

Root cause

build_logo_meta() calls Core\build_retina_image_meta(), which stores the return value of wp_get_attachment_metadata() in the 'meta' key. That function returns false for attachments with no registered metadata — common for logos uploaded before image sizes were defined or for SVG files.

The code then immediately writes into $image_meta['meta']['image_meta']['alt'] (line 123) and reads $image_meta['meta']['height'] (line 129), both of which implicitly relied on PHP silently converting false to an array on first write. PHP 8.1 deprecated this behaviour.

Fix (applied in wp-proud-core)

Added a guard in build_logo_meta() before the first write:

if (!is_array($image_meta['meta'])) {
    $image_meta['meta'] = [];
}

When metadata is absent, height and width evaluate to 0, so the existing fallback ($custom_width = 140) already handles this correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions