-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Pattern Overrides: Initial number of number set (or $ + 2 numbers) disappear from edited Paragraph & Heading Blocks #62347
Comments
cc @talldan, @kevin940726 |
Thanks for the ping @Mamaduka, we just discovered it here too - #62220 (comment) |
I believe it is caused by this refactoring of the replacement logic: link. My fault for using regex 🤦 The idea behind that pull request was to simplify the logic to support more attributes, but that didn't make it to 6.6. We should probably go back to the previous implementation and refactor the logic once the HTML API adds new methods to help with that. |
@SantosGuillamot Thanks for the quick PR! I tried it out myself and also found a fix while keeping the regex: diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php
index d3a8b3f557..a0aca9a4e5 100644
--- a/lib/compat/wordpress-6.5/blocks.php
+++ b/lib/compat/wordpress-6.5/blocks.php
@@ -85,7 +85,9 @@ function gutenberg_block_bindings_replace_html( $block_content, $block_name, str
return $block_content;
}
$pattern = '/(<' . $selector . '[^>]*>).*?(<\/' . $selector . '>)/i';
- return preg_replace( $pattern, '$1' . wp_kses_post( $source_value ) . '$2', $block_content );
+ return preg_replace_callback( $pattern, function ( $matches ) use ( $source_value ) {
+ return $matches[1] . wp_kses_post( $source_value ) . $matches[2];
+ }, $block_content );
case 'attribute':
$amended_content = new WP_HTML_Tag_Processor( $block_content ); It seems to work. This could be an alternative solution if the regex is needed for other reasons. |
Thanks for taking a look, @kevin940726! It seems safer to revert the changes and not use regex at all. The only benefits were code readability and potentially supporting more attributes, but maybe it is better to keep it the way it was until we can refactor it when the HTML API is ready. Anyway, I'd love to know more opinions. |
Should be closed by #62355. |
This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content. It also adds a unit test to cover the regression experienced in WordPress/gutenberg#62347. Follow-up to [58298]. Props santosguillamot, gziolo. Fixes #61385. See #61351. git-svn-id: https://develop.svn.wordpress.org/trunk@58398 602fd350-edb4-49c9-b593-d223f7449a82
This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content. It also adds a unit test to cover the regression experienced in WordPress/gutenberg#62347. Follow-up to [58298]. Props santosguillamot, gziolo. Fixes #61385. See #61351. Built from https://develop.svn.wordpress.org/trunk@58398 git-svn-id: http://core.svn.wordpress.org/trunk@57847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content. It also adds a unit test to cover the regression experienced in WordPress/gutenberg#62347. Follow-up to [58298]. Props santosguillamot, gziolo. Fixes #61385. See #61351. Built from https://develop.svn.wordpress.org/trunk@58398 git-svn-id: https://core.svn.wordpress.org/trunk@57847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Description
While using Synced Pattern Overrides on a pattern to display prices on a Paragraph Block for a restaurant menu, I noticed that the "$" and next two numbers of the price would not display on the website front end after editing from the original. Additionally, if I used only numbers for the price and no "$", I noticed that the first number of the set of numbers does not display on the front end (looks normal in the editor). The same issue happens with the "Headings" block when part of a Pattern Override.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Images show the Pattern Override after editing the price - and the result on the website front end.
Environment info
Environment
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: