这是indexloc提供的服务,不要输入任何密码
Skip to content

Avoid possibility of ob_start() being called during output buffer processing (to avoid fatal error) #6232

@westonruter

Description

@westonruter

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

  1. Activate the latest Gutenberg.
  2. Add the above PHP code to a plugin.
  3. View an AMP page.
  4. See fatal error.

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions