Skip to content
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

Introduce strip_dynamic_blocks() for excerpts #8984

Merged
merged 4 commits into from Aug 16, 2018

Conversation

obenland
Copy link
Member

Description

Aims to fix #7268 by adding parity with strip_shortcodes() in wp_trim_excerpt().
Aims to fix #5572 by removing dynamic blocks when generating excerpts to avoid infinite loops when dynamic blocks generate excerpts themselves.

How has this been tested?

I created a dynamic block that generated an excerpt in its callback, embedded it, and tested that it didn't create an out-of-memory error. Also added a small unit test to verify dynamic blocks are stripped.

Types of changes

  • Moves generating dynamic block regex into its own function, similar to get_shortcode_regex().
  • Introduces strip_dynamic_blocks() function.
  • Introduces a unit test for strip_dynamic_blocks().
  • Calls strip_dynamic_blocks() when generating an excerpt.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

Initially used when generating excerpts to avoid infinite loops when dynamic blocks generate excerpts, and to add parity with `strip_shortcodes()`.
Incompatible with PHP 5.2
@obenland obenland added [Type] Enhancement A suggestion for improvement. [Feature] Block API API that allows to express the block paradigm. labels Aug 14, 2018
@obenland obenland added this to the WordPress 5.0 milestone Aug 14, 2018
@obenland obenland requested review from pento and aduth August 14, 2018 16:10
@obenland obenland changed the title Origin/add/strip dynamic blocks Introduce strip_dynamic_blocks() for excerpts Aug 14, 2018
@obenland obenland changed the title Introduce strip_dynamic_blocks() for excerpts Introduce strip_dynamic_blocks() for excerpts Aug 14, 2018
@mtias mtias mentioned this pull request Aug 15, 2018
16 tasks
Copy link
Member

@pento pento left a comment

Choose a reason for hiding this comment

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

This approach works for me: dynamic blocks are functionally equivalent to shortcodes for this use case, it's quite reasonable to just strip them out. Nice work on the hack to get around the lack of convenient filter. 😉

The docblocks need to be filled out, but the implementation is otherwise good. Feel free to merge once you've updated them. 🙂

@obenland obenland merged commit 72da0cd into master Aug 16, 2018
@obenland obenland deleted the origin/add/strip-dynamic-blocks branch August 16, 2018 16:52
@youknowriad youknowriad modified the milestones: WordPress 5.0, 3.6 Aug 16, 2018
@maximebj
Copy link
Contributor

Very nice! Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strip Blocks from Auto-Generated Excerpts get_the_excerpt is taking PHP out of memory in a block rendering
4 participants