diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index e731f5bd5b..0d21094b0d 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -235,6 +235,7 @@ function get_block_metadata_i18n_schema() { * @since 5.5.0 * @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields. * @since 5.9.0 Added support for `variations` and `viewScript` fields. + * @since 6.1.0 Added support for `render` field. * * @param string $file_or_folder Path to the JSON file with metadata definition for * the block or path to the folder where the `block.json` file is located. @@ -345,6 +346,33 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { ); } + if ( ! empty( $metadata['render'] ) ) { + $template_path = wp_normalize_path( + realpath( + dirname( $metadata['file'] ) . '/' . + remove_block_asset_path_prefix( $metadata['render'] ) + ) + ); + if ( file_exists( $template_path ) ) { + /** + * Renders the block on the server. + * + * @since 6.1.0 + * + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. + * + * @return string Returns the block content. + */ + $settings['render_callback'] = function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + ob_start(); + require $template_path; + return ob_get_clean(); + }; + } + } + /** * Filters the settings determined from the block type metadata. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 0a477f71bb..e3d8ab83d4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54131'; +$wp_version = '6.1-alpha-54132'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.