Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
update regex
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Jan 5, 2022
1 parent f4689e6 commit e291dc3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/BlockTypes/LegacyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ public function add_alignment_class_to_wrapper( string $content, array $block )
preg_match( $first_tag, $content, $matches );

// If there is a tag, but it doesn't have a class attribute, add the class attribute.
if ( isset( $matches[0] ) && strpos( $matches[0], 'class' ) === false ) {
if ( isset( $matches[0] ) && strpos( $matches[0], ' class=' ) === false ) {
$pattern_before_tag_closing = '/.+?(?=>)/';
$matches = array();
preg_match( $pattern_before_tag_closing, $content, $matches );
return preg_replace( $pattern_before_tag_closing, $matches[0] . ' class="' . $align_class_and_style['class'] . '"', $content, 1 );
}

// If there is a tag, and it has a class already, add the class attribute.
$pattern_get_class = '/(?<=class=\")[^"]+(?=\")/';
$pattern_get_class = '/(?<=class=\"|\')[^"|\']+(?=\"|\')/';
$matches_class = array();
preg_match( $pattern_get_class, $content, $matches_class );
return preg_replace( $pattern_get_class, $matches_class[0] . ' ' . $align_class_and_style['class'], $content, 1 );
Expand Down

0 comments on commit e291dc3

Please sign in to comment.