@@ -102,7 +102,6 @@ function do_blocks( $content ) {
102
102
$ open_matcher = '/<!--\s*wp:([a-z](?:[a-z0-9\/]+)*)\s+((?:(?!-->).)*)-->.*<!--\s*\/wp:\g1\s+-->/ ' ;
103
103
preg_match_all ( $ open_matcher , $ content , $ matches , PREG_OFFSET_CAPTURE );
104
104
105
- $ offset = 0 ;
106
105
$ new_content = $ content ;
107
106
foreach ( $ matches [ 0 ] as $ index => $ block_match ) {
108
107
$ block_name = $ matches [ 1 ][ $ index ][ 0 ];
@@ -111,7 +110,7 @@ function do_blocks( $content ) {
111
110
continue ;
112
111
}
113
112
114
- $ block_length = mb_strlen ( $ block_match [ 0 ] ) ;
113
+ $ block_markup = $ block_match [ 0 ];
115
114
$ block_position = $ block_match [ 1 ];
116
115
$ block_attributes_string = $ matches [ 2 ][ $ index ][ 0 ];
117
116
$ block_attributes = parse_block_attributes ( $ block_attributes_string );
@@ -120,11 +119,7 @@ function do_blocks( $content ) {
120
119
$ output = call_user_func ( $ registered_blocks [ $ block_name ][ 'render ' ], $ block_attributes );
121
120
122
121
// Replace the matched block with the dynamic output
123
- $ new_content =
124
- mb_substr ( $ new_content , 0 , $ block_position + $ offset ) .
125
- $ output .
126
- mb_substr ( $ new_content , $ block_position + $ block_length + $ offset );
127
- $ offset += mb_strlen ( $ output ) - mb_strlen ( $ block_length );
122
+ $ new_content = str_replace ( $ block_markup , $ output , $ new_content );
128
123
}
129
124
130
125
return $ new_content ;
0 commit comments