diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index 7f105022..4a2a1bcf 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -101,10 +101,6 @@ private static function get_text_replacement_patterns_for_html( $block_name ) { return array( '/(
]*>)(.*?)(<\/pre>)/' ); case 'core/button': return array( '/(]*>)(.*?)(<\/a>)/' ); - case 'core/image': - case 'core/cover': - case 'core/media-text': - return array( '/alt="(.*?)"/' ); case 'core/quote': case 'core/pullquote': return array( @@ -117,6 +113,16 @@ private static function get_text_replacement_patterns_for_html( $block_name ) { '/(]*>)(.*?)(<\/th>)/', '/( ]*>)(.*?)(<\/figcaption>)/', ); + case 'core/video': + return array( '/( ]*>)(.*?)(<\/figcaption>)/' ); + case 'core/image': + return array( + '/( ]*>)(.*?)(<\/figcaption>)/', + '/(alt=")(.*?)(")/', + ); + case 'core/cover': + case 'core/media-text': + return array( '/(alt=")(.*?)(")/' ); default: return null; } @@ -158,19 +164,7 @@ public static function escape_text_content_of_blocks( $blocks ) { case 'core/quote': case 'core/pullquote': case 'core/table': - $replace_content_callback = function ( $content, $pattern ) { - if ( empty( $content ) ) { - return; - } - return preg_replace_callback( - $pattern, - function( $matches ) { - return $matches[1] . self::escape_text_content( $matches[2] ) . $matches[3]; - }, - $content - ); - }; - break; + case 'core/video': case 'core/image': case 'core/cover': case 'core/media-text': @@ -181,7 +175,11 @@ function( $matches ) { return preg_replace_callback( $pattern, function( $matches ) { - return 'alt="' . self::escape_attribute( $matches[1] ) . '"'; + // If the pattern is for attribute like alt="". + if ( str_ends_with( $matches[1], '="' ) ) { + return $matches[1] . self::escape_attribute( $matches[2] ) . $matches[3]; + } + return $matches[1] . self::escape_text_content( $matches[2] ) . $matches[3]; }, $content ); diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 50e85891..40c4f631 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -125,12 +125,12 @@ public function data_test_escape_text_content_of_blocks() { 'image' => array( 'block_markup' => - ' - + ' + ', 'expected_markup' => - ' - + ' + ', ), @@ -186,6 +186,15 @@ public function data_test_escape_text_content_of_blocks() { ', ), + 'video' => array( + 'block_markup' => ' + +', + 'expected_markup' => + ' + +', + ), ); } }