@@ -101,10 +101,6 @@ private static function get_text_replacement_patterns_for_html( $block_name ) {
101
101
return array ( '/(<pre[^>]*>)(.*?)(<\/pre>)/ ' );
102
102
case 'core/button ' :
103
103
return array ( '/(<a[^>]*>)(.*?)(<\/a>)/ ' );
104
- case 'core/image ' :
105
- case 'core/cover ' :
106
- case 'core/media-text ' :
107
- return array ( '/alt="(.*?)"/ ' );
108
104
case 'core/quote ' :
109
105
case 'core/pullquote ' :
110
106
return array (
@@ -117,6 +113,16 @@ private static function get_text_replacement_patterns_for_html( $block_name ) {
117
113
'/(<th[^>]*>)(.*?)(<\/th>)/ ' ,
118
114
'/(<figcaption[^>]*>)(.*?)(<\/figcaption>)/ ' ,
119
115
);
116
+ case 'core/video ' :
117
+ return array ( '/(<figcaption[^>]*>)(.*?)(<\/figcaption>)/ ' );
118
+ case 'core/image ' :
119
+ return array (
120
+ '/(<figcaption[^>]*>)(.*?)(<\/figcaption>)/ ' ,
121
+ '/(alt=")(.*?)(")/ ' ,
122
+ );
123
+ case 'core/cover ' :
124
+ case 'core/media-text ' :
125
+ return array ( '/(alt=")(.*?)(")/ ' );
120
126
default :
121
127
return null ;
122
128
}
@@ -158,19 +164,7 @@ public static function escape_text_content_of_blocks( $blocks ) {
158
164
case 'core/quote ' :
159
165
case 'core/pullquote ' :
160
166
case 'core/table ' :
161
- $ replace_content_callback = function ( $ content , $ pattern ) {
162
- if ( empty ( $ content ) ) {
163
- return ;
164
- }
165
- return preg_replace_callback (
166
- $ pattern ,
167
- function ( $ matches ) {
168
- return $ matches [1 ] . self ::escape_text_content ( $ matches [2 ] ) . $ matches [3 ];
169
- },
170
- $ content
171
- );
172
- };
173
- break ;
167
+ case 'core/video ' :
174
168
case 'core/image ' :
175
169
case 'core/cover ' :
176
170
case 'core/media-text ' :
@@ -181,7 +175,11 @@ function( $matches ) {
181
175
return preg_replace_callback (
182
176
$ pattern ,
183
177
function ( $ matches ) {
184
- return 'alt=" ' . self ::escape_attribute ( $ matches [1 ] ) . '" ' ;
178
+ // If the pattern is for attribute like alt="".
179
+ if ( str_ends_with ( $ matches [1 ], '=" ' ) ) {
180
+ return $ matches [1 ] . self ::escape_attribute ( $ matches [2 ] ) . $ matches [3 ];
181
+ }
182
+ return $ matches [1 ] . self ::escape_text_content ( $ matches [2 ] ) . $ matches [3 ];
185
183
},
186
184
$ content
187
185
);
0 commit comments