[wp-trac] [WordPress Trac] #42513: WP_Theme::get_post_templates() is extremely inefficient for large themes
WordPress Trac
noreply at wordpress.org
Fri Apr 10 08:56:54 UTC 2026
#42513: WP_Theme::get_post_templates() is extremely inefficient for large themes
-------------------------------------------------+-------------------------
Reporter: gschoppe | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Themes | Version: 4.8.3
Severity: normal | Resolution:
Keywords: good-first-bug has-patch has-unit- | Focuses:
tests | performance
-------------------------------------------------+-------------------------
Comment (by MythThrazz):
New PR in #11545 replacing PR #8310 with a more comprehensive fix:
- Replaces dual `file_get_contents()` with a single `get_file_data()`
call (reads only first 8KB instead of the
entire file)
- Moves `get_block_templates()` inside the cache block to avoid a DB
query on every call
- Includes unit tests
The blocker from #42517 (single-line header support) appears to be
resolved — `get_file_data()` regex already
handles `<?php // Template Name: ... ?>` format, confirmed by existing
tests in
`tests/phpunit/data/themedir1/page-templates/template-header.php`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42513#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list