Open spacedmonkey opened 5 years ago
Feels like a fatal error would be a really good indication for a developer that they're doing something wrong, no? :-) Returning an empty array or something would be like error silencing in this case.
I am more thinking about users if something goes wrong. How about something like this
function gutenberg_parse_blocks( $content ) {
$default = 'WP_Block_Parser';
/**
* Filter to allow plugins to replace the server-side block parser
*
* @since 3.8.0
*
* @param string $parser_class Name of block parser class
*/
$parser_class = apply_filters( 'block_parser_class', $default );
// Load default block parser for server-side parsing if the default parser class is being used.
if( ! class_exists( $parser_class ) ){
_doing_it_wrong( __FUNCTION__, 'Unable to find class $parser_class to parse content', '5.0.0' );
$parser_class = $default;
}
if ( 'WP_Block_Parser' === $parser_class ) {
require_once dirname( __FILE__ ) . '/../packages/block-serialization-default-parser/parser.php';
}
$parser = new $parser_class();
return $parser->parse( $content );
}
Just so users never get a white screen and it still renders.
@spacedmonkey After 4 years, has this already been resolved? And if not, could you summarize what's still needed for this issue to be closed?
Describe the bug If
parse_blocks
andgutenberg_parse_blocks
gives you a filter to change the parser class. SeeAfter this line, it should check to see if they class existings, because instantiating the class, to stop getting a fatal error.