-
Notifications
You must be signed in to change notification settings - Fork 798
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
Carousel: improve detection of containers where we should add data #13446
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: October 1, 2019. |
Fixes #13428 Until now we would rely on 2 str_replace to add Carousel data to div and ul containers in post content. This worked, but wasn't smart enough to know to ignore specific divs like Columns blocks. By using DOMDocument, we can go through the post content in a more readable way, to detect gallery blocks as well as regular galleries and images.
474d368
to
ebb2a70
Compare
jeherve, Your synced wpcom patch D32610-code has been updated. |
jeherve, Your synced wpcom patch D32610-code has been updated. |
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.
I don't think it strictly matters for this use case, but we should wrap the DOM usage in:
$old_libxml_disable_entity_loader = libxml_disable_entity_loader( true );
// … DOM use
libxml_disable_entity_loader( $old_libxml_disable_entity_loader );
foreach ( $div_tags as $div_tag ) { | ||
if ( | ||
false === strpos( $div_tag->getAttribute( 'class' ), 'wp-block-' ) | ||
|| false !== strpos( $div_tag->getAttribute( 'class' ), 'gallery' ) |
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.
Should this be &&
?
As written, we add the attribute to all divs that are not wp-block-
divs (including divs with no class at all).
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.
That's the current behaviour, I didn't want to change that. We currently add the attributes to all divs. With this change, it will be added to all divs, except if they include a class including wp-block-
. The second parameter is here to add an additional exception: wp-block-
is okay if it's a gallery block, like wp-block-jetpack-tiled-gallery
.
Maybe there would be a more readable way to do that? Or should we instead move to more of a whitelist where we don't add the data to all the divs, but only to some specific ones?
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.
I'd support keeping the behavior the way it is for the sake of the PR, but open an enhancement issue to explore refactoring it.
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.
Logged in #13499
See https://github.com/Automattic/jetpack/pull/13446/files#r321866447 Co-Authored-By: Michael D Adams <michael.d.adams@gmail.com>
jeherve, Your synced wpcom patch D32610-code has been updated. |
1 similar comment
jeherve, Your synced wpcom patch D32610-code has been updated. |
See https://github.com/Automattic/jetpack/pull/13446/files#r321867238 Co-Authored-By: Michael D Adams <michael.d.adams@gmail.com>
905aac7
to
b2a0560
Compare
jeherve, Your synced wpcom patch D32610-code has been updated. |
jeherve, Your synced wpcom patch D32610-code has been updated. |
I've added the libxml_disable_entity_loader check as well 👍
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.
I did some performance testing locally of the the_content
filter before and after with a very large post (105k words, ~750k characters). There didn't seem to be a functional difference between them.
* Changelog: initial set of changes for 7.8 * Changelog: add #13310 * Changelog: add #13103 * Changelog: add #13426 * Changelog: add #13389 * Changelog: add #13449 * Changelog: add #13461 * Changelog: add #13460 * Changelog: add #13441 * Changelog: add #13454 * Changelog: add #13457 * Changelog: add #13425 * Changelog: add #13473 * Changelog: add #13355 * Changelog: add #13451 * Changelog: add #13358 * Changelog: add #13464 * Changelog: add #13416 * Changelog: add #13494 * Changelog: add #13465 * Changelog: add #13424 * Changelog: add #13432 * Changelog: add #13471 * Changelog: add 7.7.2 entry * Changelog: add #13446 * Add more testing elements
* Changelog: initial set of changes for 7.8 * Changelog: add #13310 * Changelog: add #13103 * Changelog: add #13426 * Changelog: add #13389 * Changelog: add #13449 * Changelog: add #13461 * Changelog: add #13460 * Changelog: add #13441 * Changelog: add #13454 * Changelog: add #13457 * Changelog: add #13425 * Changelog: add #13473 * Changelog: add #13355 * Changelog: add #13451 * Changelog: add #13358 * Changelog: add #13464 * Changelog: add #13416 * Changelog: add #13494 * Changelog: add #13465 * Changelog: add #13424 * Changelog: add #13432 * Changelog: add #13471 * Changelog: add 7.7.2 entry * Changelog: add #13446 * Add more testing elements
…uld add data (#13446) * Carousel: improve detection of containers where we should add data Fixes #13428 Until now we would rely on 2 str_replace to add Carousel data to div and ul containers in post content. This worked, but wasn't smart enough to know to ignore specific divs like Columns blocks. By using DOMDocument, we can go through the post content in a more readable way, to detect gallery blocks as well as regular galleries and images. * Bail if the server does not support DOMDocument * Store and return value from libxml_use_internal_errors See https://github.com/Automattic/jetpack/pull/13446/files#r321866447 Co-Authored-By: Michael D Adams <michael.d.adams@gmail.com> * No need to escape data key See https://github.com/Automattic/jetpack/pull/13446/files#r321867238 Co-Authored-By: Michael D Adams <michael.d.adams@gmail.com> * Wrap DOM usage in libxml_disable_entity_loader See #13446 (review)
Cherry-picked to |
Fixes #13428
Changes proposed in this Pull Request:
Until now we would rely on 2 str_replace to add Carousel data to div and ul containers in post content.
This worked, but wasn't smart enough to know to ignore specific divs like Columns blocks.
By using DOMDocument, we can go through the post content in a more readable way, to detect gallery blocks as well as regular galleries and images.
Testing instructions:
Proposed changelog entry for your changes: