diff --git a/includes/create-theme/theme-media.php b/includes/create-theme/theme-media.php index e9bbcab7..e0418e88 100644 --- a/includes/create-theme/theme-media.php +++ b/includes/create-theme/theme-media.php @@ -462,8 +462,12 @@ public static function make_template_images_local( $template, $media_to_localize // but accepts a leading `/` unchanged. The path uses characters // that wp_json_encode leaves untouched as well. $placeholders = array(); - $next_placeholder = static function ( $raw ) use ( &$placeholders ) { - $id = '/__cbt-local-media-' . count( $placeholders ) . '__'; + $source_content = $template->content; + $next_placeholder = static function ( $raw ) use ( &$placeholders, $source_content ) { + do { + $id = '/__cbt-local-media-' . wp_generate_uuid4() . '-' . count( $placeholders ) . '__/'; + } while ( false !== strpos( $source_content, $id ) || isset( $placeholders[ $id ] ) ); + $placeholders[ $id ] = $raw; return $id; }; diff --git a/tests/test-theme-media.php b/tests/test-theme-media.php index c552407a..09191e68 100644 --- a/tests/test-theme-media.php +++ b/tests/test-theme-media.php @@ -331,6 +331,28 @@ public function test_make_template_images_local_only_rewrites_validated_media() $this->assertStringNotContainsString( '/assets/images/not-copied.png', $new_template->content ); } + public function test_make_template_images_local_preserves_placeholder_like_content() { + $template = new stdClass(); + $template->content = ' + +
Keep /__cbt-local-media-0__/ unchanged.
+ + +