Skip to content

Commit

Permalink
Simplify preg_match results
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lende committed Aug 24, 2022
1 parent e78d490 commit 1ccd556
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,19 +547,15 @@ function gutenberg_render_block_wrapper_attributes( $block_content, $new_attribu

$attribute_pattern = '/'. preg_quote( $attribute_name, '/' ) . '="([^"]*)"/';
$wrapper_pattern = '/<[^>]+?' . substr( $attribute_pattern, 1, -1 ) . '[^>]*>/';
$match_result = preg_match(
preg_match(
$wrapper_pattern,
$block_content,
$matches
);

if ( isset( $matches[1] ) ) {
$extra_attribute = $matches[1];
}

if ( 1 === $match_result ) {
// Replace the attribute.
$value = $new_attributes[ $attribute_name ] . ' ' . $extra_attribute;
$value = $new_attributes[ $attribute_name ] . ' ' . $matches[1];
$block_content = preg_replace(
$attribute_pattern,
sprintf( '%s="%s"', $attribute_name, esc_attr( $value ) ),
Expand Down

0 comments on commit 1ccd556

Please sign in to comment.