diff --git a/mu-plugins/blocks/link-wrapper/index.php b/mu-plugins/blocks/link-wrapper/index.php index f96260c79..6810e02e9 100644 --- a/mu-plugins/blocks/link-wrapper/index.php +++ b/mu-plugins/blocks/link-wrapper/index.php @@ -20,5 +20,32 @@ * @see https://developer.wordpress.org/reference/functions/register_block_type/ */ function init() { - register_block_type( __DIR__ . '/build' ); + register_block_type( + __DIR__ . '/build', + array( + 'render_callback' => __NAMESPACE__ . '\render', + ) + ); +} + +/** + * Renders the Link Wrapper block. + * + * @param array $attributes Block attributes. + * @param string $content Block content. + * @return string Rendered block HTML. + */ +function render( $attributes, $content, $block ) { + $post_id = $block->context['postId']; + $post_slug = get_post_field( 'post_name', $post_id ); + $link = isset( $attributes['url'] ) ? ' ' . $attributes['url'] : site_url( $post_slug ); + + $wrapper_attributes = get_block_wrapper_attributes(); + + return sprintf( + '%3$s', + esc_url( $link ), + $wrapper_attributes, + do_blocks( $content ) + ); } diff --git a/mu-plugins/blocks/link-wrapper/src/block.json b/mu-plugins/blocks/link-wrapper/src/block.json index 2c647ec0d..01a99d083 100644 --- a/mu-plugins/blocks/link-wrapper/src/block.json +++ b/mu-plugins/blocks/link-wrapper/src/block.json @@ -6,6 +6,7 @@ "icon": "admin-links", "category": "layout", "description": "Link a set of blocks to a given page.", + "usesContext": [ "postId" ], "textdomain": "wporg", "attributes": { "url": { @@ -30,6 +31,9 @@ "padding": true } }, + "dimensions": { + "minHeight": true + }, "typography": { "fontSize": true, "lineHeight": true diff --git a/mu-plugins/blocks/link-wrapper/src/index.js b/mu-plugins/blocks/link-wrapper/src/index.js index 3396ecb9a..54287b1ad 100644 --- a/mu-plugins/blocks/link-wrapper/src/index.js +++ b/mu-plugins/blocks/link-wrapper/src/index.js @@ -24,6 +24,7 @@ function Edit( { attributes, setAttributes } ) { <> +

{ __( 'Defaults to the permalink if not set.', 'wporg' ) }

{ - const blockProps = useBlockProps.save(); - return ( - - - - ); + save: () => { + return ; }, } );