-
Notifications
You must be signed in to change notification settings - Fork 382
Description
Bug Description
In a support topic it was discovered that the AmpSchemaOrgMetadata
transformer (and specifically AmpSchemaOrgMetadataConfiguration
) can cause a fatal error:
PHP Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in /app/public/content/plugins/gutenberg/build/block-library/blocks/post-comments-form.php on line 26
The issue is that the the transformer configurations are obtained during the output buffer callback, and so if there is any code that tries to do ob_start()
in any WordPress code that applies the amp_schemaorg_metadata
filter then this error will occur. For example, in Gutenberg the Post Comments Form block uses output buffering in its render_callback
, so the following plugin code causes a fatal error on AMP pages:
add_filter( 'amp_schemaorg_metadata', function ( $metadata ) {
$metadata['rendered_post_comments_form'] = do_blocks( '<!-- wp:post-comments-form /-->' );
return $metadata;
} );
Or more simply without the Gutenberg dependency:
add_filter( 'amp_schemaorg_metadata', function ( $metadata ) {
ob_start();
echo 'Hello!';
$metadata['buffered'] = ob_get_clean();
return $metadata;
} );
This causes the fatal error.
Expected Behaviour
No call to ob_start()
should be possible during AMP_Theme_Support::prepare_response()
.
Steps to reproduce
- Activate the latest Gutenberg.
- Add the above PHP code to a plugin.
- View an AMP page.
- See fatal error.
Do not alter or remove anything below. The following sections will be managed by moderators only.