-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try fixing that v1 markup on published pages #2290
Conversation
Download coblocks.zip: https://46451-128991767-gh.circle-artifacts.com/0/tmp/artifacts/coblocks-2290.zip |
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job figuring this one out! Minor change requested and then you can merge it.
* @return boolean True when post content contains a v1 Masonry block. | ||
*/ | ||
public function has_masonry_v1_block() { | ||
$v1_regex = '/<!-- wp:coblocks\/gallery-masonry.*|\n*(coblocks-gallery--item).*|\n*<!-- \/wp:coblocks\/gallery-masonry -->/m'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need the multi-line flag (/m
) here because you're not using the beginning string (^
) and end of string ($
) modifiers. Just the slash without any flags would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posting here for reference a possible new regex so we can simplify the function: https://regex101.com/r/xESuJM/1
/<!--\s+?wp:coblocks\/gallery-masonry[\s\S]*?coblocks-gallery--item/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also work:
/<!--\s+?wp:coblocks\/gallery-masonry.*?coblocks-gallery--item/s
preg_match_all( $v1_regex, get_the_content(), $matches ); | ||
return isset( $matches[0] ) && isset( $matches[0][2] ) && ! empty( $matches[0][2] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to store and perform conditions on any of the matches, we just want to know if there is a match. This can be simplified with:
return preg_match( $v1_regex, get_the_content() );
We ended up coming across a few issues and edge cases with regex that will adequately match the V1 masonry block. There is one known edge case that will cause users to superfluously load Masonry/jQuery scripts. Edge Case
|
Deciding to keep changes after discussion
Description
In cases where users have old V1 masonry markup already saved and on published pages we have broken galleries. This fallback will allow for the old Masonry markup to continue to function as expected.
Note
We ended up coming across a few issues and edge cases with regex that will adequately match the V1 masonry block.
There is one known edge case that will cause users to superfluously load Masonry/jQuery scripts.
Edge Case
If a user has V2 Masonry > (Offset Gallery OR Carousel Gallery) > V2 Masonry.
Screenshots
Before
After
Types of changes
Re-Introduce jQuery as a fallback :(
How has this been tested?
Tested manually.