What
includes/create-theme/theme-templates.php:233 reads $template->media without checking whether the property exists on the WP_Block_Template object:
// Write the media assets if there are any
if ( $template->media ) {
CBT_Theme_Media::add_media_to_local( $template->media );
}
The media property is only attached by prepare_template_for_export() on code paths where there is image media to localize. On every other path the property is simply absent — and this line reads it unconditionally.
When it triggers
- PHP 8.2+ emits a
Deprecated: Creation of dynamic property / Undefined property notice on every save where a template has no media to localize (i.e. most saves).
- PHP 9 will turn this into a warning.
- It does not currently break anything functionally — it just leaks notices into the PHP error log.
How it was discovered
Surfaced by a strict error handler in the new PHPUnit regression test added in #833. That test was narrowed to only catch the processOnlySavedTemplates regression so it does not fail on this unrelated pre-existing issue.
Suggested fix
One-line change at theme-templates.php:233:
- if ( $template->media ) {
+ if ( ! empty( $template->media ) ) {
! empty() returns false for both undefined and falsy values, so the existing behavior is preserved for the cases where the property is set.
Notes
What
includes/create-theme/theme-templates.php:233reads$template->mediawithout checking whether the property exists on theWP_Block_Templateobject:The
mediaproperty is only attached byprepare_template_for_export()on code paths where there is image media to localize. On every other path the property is simply absent — and this line reads it unconditionally.When it triggers
Deprecated: Creation of dynamic property/Undefined propertynotice on every save where a template has no media to localize (i.e. most saves).How it was discovered
Surfaced by a strict error handler in the new PHPUnit regression test added in #833. That test was narrowed to only catch the
processOnlySavedTemplatesregression so it does not fail on this unrelated pre-existing issue.Suggested fix
One-line change at
theme-templates.php:233:! empty()returnsfalsefor both undefined and falsy values, so the existing behavior is preserved for the cases where the property is set.Notes
CBT_Theme_Saveextraction) per that issue's scope guarantees.! empty()) is worth a quick scan across the file for sibling property reads on$template— there may be similar reads elsewhere.