Skip to content

Fix blocks props logic#199

Open
nelsonamaya82 wants to merge 1 commit intomasterfrom
blocks-props-fix
Open

Fix blocks props logic#199
nelsonamaya82 wants to merge 1 commit intomasterfrom
blocks-props-fix

Conversation

@nelsonamaya82
Copy link
Contributor

@nelsonamaya82 nelsonamaya82 commented Jun 11, 2020

In this PR I added some extra validations to the methods that add properties to some Gutenberg blocks to make sure the properties are added/modified in the block opening part only, instead of any part of the block content.

It also fixes a bug in the lean_column_props method that removed any attribute with the style= substring in the block content, e.g. data-style= (and not only the style attribute, as expected).


$close_pos = strpos( $block_content, '>' );
$data_type_pos = strpos( $block_content, 'data-type' );
if ( false !== $close_pos && false === $data_type_pos ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could have simply kept it as was and changed the if as follows:

if ( false !== $close_pos && ( false === $data_type_pos || $data_type_pos > $close_pos ) ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially considered that solution, but I think it's more performant to search for the data-type attribute just in the opening tag of the block instead of the whole block content (e.g. if the block had a lot of content and just at the end an element with this data attribute).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants