From 093805e01fb2a55540a0256238754d3de25b7d55 Mon Sep 17 00:00:00 2001 From: Birgit Pauli-Haack Date: Tue, 5 May 2026 17:30:29 +0200 Subject: [PATCH] Fix: guard `$template->media` reads against undefined property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `add_templates_to_local()` reads `$template->media` in two places (templates loop, template parts loop) without checking whether the property exists. 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, accessing it raises a PHP 8.2+ deprecation notice ("Creation of dynamic property" / "Undefined property: WP_Block_Template::\$media"). Wrap both reads with `! empty()`, mirroring the convention already used a few lines later for `$template->pattern`. Existing behavior is preserved: `! empty()` returns false for both undefined and falsy values. Closes #834 --- includes/create-theme/theme-templates.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/create-theme/theme-templates.php b/includes/create-theme/theme-templates.php index d40da394..37a3648e 100644 --- a/includes/create-theme/theme-templates.php +++ b/includes/create-theme/theme-templates.php @@ -230,7 +230,7 @@ public static function add_templates_to_local( $export_type, $path = null, $slug ); // Write the media assets if there are any - if ( $template->media ) { + if ( ! empty( $template->media ) ) { CBT_Theme_Media::add_media_to_local( $template->media ); } @@ -258,7 +258,7 @@ public static function add_templates_to_local( $export_type, $path = null, $slug ); // Write the media assets if there are any - if ( $template->media ) { + if ( ! empty( $template->media ) ) { CBT_Theme_Media::add_media_to_local( $template->media ); }