Skip to content

Conversation

@Omcodes23
Copy link

Fix: Localize repeated background images in Cover block

Summary

Localizes images used as “repeated background” in core/cover when “Localize images” is enabled. These images are copied into the theme’s assets and referenced via theme-relative URLs, removing dependency on the original uploads directory.

Fixes

Changes

  • includes/create-theme/theme-media.php
    • Enhance background-image URL parsing to support quoted and unquoted url(...).
    • Collect attrs.style.background.backgroundImage.url (Cover’s “Repeat background” attribute path).
  • tests/test-theme-templates.php
    • Add test_localize_cover_repeated_background_via_attrs() to verify attribute-defined repeated backgrounds localize to /assets/images/bg.png and are replaced with a theme-relative URL.
    • Add test_localize_cover_repeated_background_inline_style() to verify inline background-image:url(...) repeated backgrounds localize to /assets/images/pattern.webp.

Rationale

Repeated background images set via the Cover block’s attributes were missed, leaving absolute upload URLs. The media extractor now covers both inline CSS and attribute-defined backgrounds to align with “Localize images”.

Risk/Compatibility

  • Scoped to media extraction logic for Cover/Group backgrounds.
  • Follows existing asset path conventions (/assets/images/) and parent/child theme URL handling.

Testing

  • Two new unit tests cover attribute and inline style scenarios alongside existing localization tests.

Checklist

  • Changes are limited to localization of Cover repeated backgrounds
  • Unit tests added
  • No breaking changes to existing APIs or behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant