-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
get_the_excerpt is taking PHP out of memory in a block rendering #5572
Comments
Hey Maxime, could you clarify what you're doing on this step?
I'd like to try to test this. |
Yes ! I'm creating some blocks (and making a plugin of it) and one of my block is about featuring another post like this : So my block in html is just
And the whole thing is rendered via PHP. When I'm in the render_callback, if I try to call get_excerpt() I got this error |
And when might we expect a solution? Seems like I'm not the only one who sees this as an urgent and blocking problem... |
@Theremingenieur are you working inside a I'm seeing the same behavior, but am also seeing some interesting differences depending on how I attempt to display results. Attempting to debug. |
The issue is not there if I make a standard The issue only occurs when I use I don't understand why there is a difference, but if it can help. Thank you! |
I think this happens when the excerpt is empty for a post because:
It seems core ends up avoiding the fatal error because it calls Stack trace``` # | Time | Memory | Function | Location -- | -- | -- | -- | -- 1 | 0.2005 | 398640 | {main}( ) | .../index.php:0 2 | 0.2010 | 398928 | require( '/app/public/wp-blog-header.php' ) | .../index.php:17 3 | 0.2864 | 2905128 | require_once( '/app/public/wp-includes/template-loader.php' ) | .../wp-blog-header.php:19 4 | 0.2890 | 2947912 | include( '/app/public/wp-content/themes/twentysixteen/single.php' ) | .../template-loader.php:74 5 | 0.3255 | 3075008 | get_template_part( ) | .../single.php:19 6 | 0.3255 | 3075584 | locate_template( ) | .../general-template.php:155 7 | 0.3259 | 3075696 | load_template( ) | .../template.php:647 8 | 0.3262 | 3076056 | require( '/app/public/wp-content/themes/twentysixteen/template-parts/content-single.php' ) | .../template.php:690 9 | 0.3268 | 3076056 | the_content( ) | .../content-single.php:22 10 | 0.3268 | 3076192 | apply_filters( ) | .../post-template.php:240 11 | 0.3268 | 3076592 | WP_Hook->apply_filters( ) | .../plugin.php:203 12 | 0.3269 | 3078496 | do_blocks( ) | .../class-wp-hook.php:286 13 | 0.3270 | 3082240 | WP_Block_Type->render( ) | .../blocks.php:181 14 | 0.3270 | 3082240 | {closure:/app/public/wp-content/plugins/demo-talk/php/latest-author-post.php:5-45}( ) | .../class-wp-block-type.php:107 15 | 0.3294 | 3103048 | get_the_excerpt( ) | .../latest-author-post.php:35 16 | 0.3294 | 3103496 | apply_filters( ) | .../post-template.php:397 17 | 0.3294 | 3103896 | WP_Hook->apply_filters( ) | .../plugin.php:203 18 | 0.3294 | 3105400 | wp_trim_excerpt( ) | .../class-wp-hook.php:288 19 | 0.3294 | 3105512 | apply_filters( ) | .../formatting.php:3313 20 | 0.3294 | 3105912 | WP_Hook->apply_filters( ) | .../plugin.php:203 21 | 0.3294 | 3106664 | do_blocks( ) | .../class-wp-hook.php:286 22 | 0.3295 | 3110408 | WP_Block_Type->render( ) | .../blocks.php:181 23 | 0.3296 | 3110408 | {closure:/app/public/wp-content/plugins/demo-talk/php/latest-author-post.php:5-45}( ) | .../class-wp-block-type.php:107 24 | 0.3306 | 3129024 | get_the_excerpt( ) | .../latest-author-post.php:35 25 | 0.3307 | 3129472 | apply_filters( ) | .../post-template.php:397 26 | 0.3307 | 3129872 | WP_Hook->apply_filters( ) | .../plugin.php:203 27 | 0.3307 | 3130624 | wp_trim_excerpt( ) | .../class-wp-hook.php:288 28 | 0.3307 | 3130736 | apply_filters( ) | .../formatting.php:3313 29 | 0.3307 | 3131136 | WP_Hook->apply_filters( ) | .../plugin.php:203 30 | 0.3307 | 3131888 | do_blocks( ) | .../class-wp-hook.php:286 31 | 0.3307 | 3135632 | WP_Block_Type->render( ) | .../blocks.php:181 ``` |
Thank you for theses valuable informations So as you say if I do a real WP Query there is no issue. And if a post has a manual excerpt there is no issue too. I may close this issue as it is not really Gutenberg related, what do you think? |
Yeah, seems more like an issue with Core and the |
Yeah, a 'normal' WP_Query doesn't help either. This is our current test setup:
It runs into memory issues as expected. |
See also #7268. |
I came up with the same issue when creating a dynamic block and using
which solves the infinite nesting and accomplishes my desired behavior. |
We could probably just remove the filter at the beginning of |
I thought that wouldn't work because if you are trying to generate an excerpt from a post with blocks, without doing the blocks, you'll end up with block comments instead of the actual content. |
To my understanding, that would only apply to dynamic blocks. Shortcodes are currently stripped too, so there should be any inconsistency there. Regular block should display fine, based on their stored markup. |
Wouldn't you still end up with the comments at top? I guess, depending on how the person is using |
Not in my testing so far. |
Ah, awesome! |
A better fix could be to just strip dynamic blocks when trying to generate an excerpt |
Issue Overview
I'm rendering a block in PHP that display another post preview card so I simply use (in the render_callabck) :
I get a Fatal error: Allowed memory size of... from PHP from get_the_excerpt()
It look like it's too much for WP to parse the gutenberg saved markup
The targeted post only has a few paragraphs and a read more tag.
The issue does not happen if I set manually an excerpt in the inspector.
This memory issue does not occur outside a block rendered in PHP
Steps to Reproduce
Expected Behavior
display everything
Current Behavior
Allowed memory size of
Todos
The text was updated successfully, but these errors were encountered: