Make WordPress Core

Opened 9 months ago

Last modified 6 weeks ago

#64778 new defect (bug)

get_block_editor_theme_styles() doesn't load editor styles of parent theme

Reported by: ocean90 Owned by:
Priority: normal Milestone: Awaiting Review
Component: Themes Version: 5.8
Severity: normal Keywords: has-patch has-test-info has-unit-tests
Cc: Focuses: template

Description

If a parent block theme uses add_editor_style( 'style-editor.css' ); and the child theme too, the style-editor.css of the parent theme is no longer loaded. This is unexpected and different from classic themes.

get_editor_stylesheets() looks in the parent theme as well while get_block_editor_theme_styles() uses get_theme_file_path() which searches in the stylesheet directory before the template directory.

The current workaround is to use a different file name in the child theme.

Change History (5)

This ticket was mentioned in ​PR #11112 on ​WordPress/wordpress-develop by ​@ocean90.


9 months ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/64778

## Use of AI Tools

None.

#2 @westonruter
9 months ago

  • Keywords needs-unit-tests added

#3 @arkaprabhachowdhury
3 months ago

  • Keywords has-test-info added

Patch Testing Report

Patch tested: ​PR #11112

Environment

  • WordPress: 7.1-alpha-20260714.092234
  • PHP: 7.4
  • Server: WordPress Playground
  • Database: SQLite
  • Browser: Chrome on Windows
  • Theme: Ticket Test Child with Ticket Test Parent
  • Plugins: None

Steps taken

  1. Created a block parent theme and child theme, both containing style-editor.css.
  2. Added add_editor_style( 'style-editor.css' ); to both themes.
  3. Added valid templates/index.html files so both themes were recognized as block themes.
  4. Activated the child theme.
  5. Opened a post in the block editor containing a paragraph and an H2 heading.
  6. Confirmed that the paragraph received the parent stylesheet's red rule and the heading received the child stylesheet's blue rule.
  7. ✅ Patch is solving the problem: both parent and child editor styles loaded successfully.

Expected result

The block editor should load the matching editor stylesheet from both the parent and child themes when both use the same filename.

Additional Notes

The test was performed in a disposable WordPress Playground instance using the PR preview.

Support Content

This ticket was mentioned in ​PR #14004 on ​WordPress/wordpress-develop by ​@therssoftware.


6 weeks ago
#4

  • Keywords has-unit-tests added; needs-unit-tests removed

Description

When a child block theme uses add_editor_style( 'style-editor.css' ) and the parent theme uses the same filename, get_block_editor_theme_styles() previously used get_theme_file_path(), which stopped searching after finding the child stylesheet directory and dropped the parent theme's editor stylesheet entirely.

This PR:

  • Updates get_block_editor_theme_styles() to check the parent template directory first when a child theme is active, loading both parent and child stylesheets in order so that child theme styles cascade and override parent styles (matching get_editor_stylesheets() for classic themes).
  • Adds defensive guards for $editor_styles to ensure it is not empty and is an array before calling array_filter(), avoiding warnings/TypeErrors in PHP 8+.
  • Adds a dedicated PHPUnit test file ​`tests/phpunit/tests/theme/getBlockEditorThemeStyles.php` with 11 tests and 15 assertions covering:
    • Parent and child theme editor styles loaded in cascading order when using the same filename.
    • Parent editor style loaded when only present in parent theme.
    • Child editor style loaded when only present in child theme.
    • Standalone theme editor style loading.
    • Empty return when editor-styles theme support is absent.
    • Empty return when $editor_styles global is null or empty.
    • Non-existent files gracefully ignored.
    • Leading slashes handled safely.
    • Remote stylesheets loaded via HTTP.
    • Deduplication and empty value filtering.

Trac ticket: https://core.trac.wordpress.org/ticket/64778
Follow-up to PR: ​https://github.com/WordPress/wordpress-develop/pull/11112

Testing Instructions

Single site suite

./vendor/bin/phpunit tests/phpunit/tests/theme/getBlockEditorThemeStyles.php

Multisite suite

./vendor/bin/phpunit -c tests/phpunit/multisite.xml tests/phpunit/tests/theme/getBlockEditorThemeStyles.php

Code Style check

./vendor/bin/phpcs src/wp-includes/block-editor.php tests/phpunit/tests/theme/getBlockEditorThemeStyles.php

Expected result: 11 tests, 15 assertions passing (100% OK), 0 PHPCS errors/warnings.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Analyzing function behavior against get_editor_stylesheets(), drafting dedicated unit tests covering edge cases and regressions, running PHPUnit and PHPCS checks. Implementation and tests were reviewed and verified locally by robelsust.

---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

---

#5 @therssoftware
6 weeks ago

Added dedicated unit tests in ​PR #14004 to fulfill the needs-unit-tests requirement.

The test suite in tests/phpunit/tests/theme/getBlockEditorThemeStyles.php covers:

  • Loading both parent and child editor styles when using the same filename, confirming child styles cascade after parent styles.
  • Loading parent editor styles when not present in child theme.
  • Loading child editor styles when only in child theme.
  • Standalone theme editor style loading.
  • Handling of themes without editor-styles support or without $editor_styles set.
  • Graceful handling of missing files, leading slashes, deduplication, and remote URLs.

All 11 tests (15 assertions) pass cleanly on both single site and multisite. PHPCS passes with 0 errors and 0 warnings.

Note: See TracTickets for help on using tickets.