Skip to content

Fatal error: Uncaught Error: Cannot use object of type WP_Block_Parser_Block as array #10047

@manake

Description

@manake

gutenberg_render_block() no longer works since 3.8.0

Fatal error: Uncaught Error: Cannot use object of type WP_Block_Parser_Block as array

/**
 * Renders a single block into a HTML string.
 *
 * @since 1.9.0
 *
 * @param  array $block A single parsed block object.
 * @return string String of rendered HTML.
 */
function gutenberg_render_block( $block ) {
	$block_name  = isset( $block['blockName'] ) ? $block['blockName'] : null;
	$attributes  = is_array( $block['attrs'] ) ? $block['attrs'] : array();
	$raw_content = isset( $block['innerHTML'] ) ? $block['innerHTML'] : null;
	if ( $block_name ) {
		$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
		if ( null !== $block_type && $block_type->is_dynamic() ) {
			return $block_type->render( $attributes );
		}
	}
	if ( $raw_content ) {
		return $raw_content;
	}
	return '';
}

I think it should be $block_name = isset( $block->blockName ) ? $block->blockName : null; etc. now.

Also, it has no handling for innerBlocks.

How to parse blocks (gutenberg_parse_blocks( $post->post_content )) and then render them manually one by one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Technical FeedbackNeeds testing from a developer perspective.[Feature] Block APIAPI that allows to express the block paradigm.[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions