diff --git a/includes/create-theme/theme-media.php b/includes/create-theme/theme-media.php index aae3e019..fa0eadf0 100644 --- a/includes/create-theme/theme-media.php +++ b/includes/create-theme/theme-media.php @@ -33,7 +33,6 @@ public static function get_media_absolute_urls_from_template( $template ) { // Gets the absolute URLs of img in these blocks if ( 'core/image' === $block['blockName'] || 'core/video' === $block['blockName'] || - 'core/cover' === $block['blockName'] || 'core/media-text' === $block['blockName'] ) { $html = new WP_HTML_Tag_Processor( $block['innerHTML'] ); @@ -58,19 +57,8 @@ public static function get_media_absolute_urls_from_template( $template ) { // Gets the absolute URLs of background images in these blocks if ( 'core/cover' === $block['blockName'] ) { - $html = new WP_HTML_Tag_Processor( $block['innerHTML'] ); - while ( $html->next_tag( 'div' ) ) { - $style = $html->get_attribute( 'style' ); - if ( $style ) { - $matches = array(); - preg_match( '/background-image: url\((.*)\)/', $style, $matches ); - if ( isset( $matches[1] ) ) { - $url = $matches[1]; - if ( CBT_Theme_Utils::is_absolute_url( $url ) ) { - $media[] = $url; - } - } - } + if ( isset( $block['attrs']['url'] ) && CBT_Theme_Utils::is_absolute_url( $block['attrs']['url'] ) ) { + $media[] = $block['attrs']['url']; } } diff --git a/tests/test-theme-media.php b/tests/test-theme-media.php index 0671a6d6..066c0db5 100644 --- a/tests/test-theme-media.php +++ b/tests/test-theme-media.php @@ -39,6 +39,21 @@ public function test_make_cover_block_local() { $this->assertStringContainsString( '/assets/images', $new_template->content ); } + public function test_make_cover_block_local_with_background_image() { + $template = new stdClass(); + $template->content = ' + +