File tree 3 files changed +31
-8
lines changed
mu-plugins/blocks/link-wrapper
3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change 20
20
* @see https://developer.wordpress.org/reference/functions/register_block_type/
21
21
*/
22
22
function init () {
23
- register_block_type ( __DIR__ . '/build ' );
23
+ register_block_type (
24
+ __DIR__ . '/build ' ,
25
+ array (
26
+ 'render_callback ' => __NAMESPACE__ . '\render ' ,
27
+ )
28
+ );
29
+ }
30
+
31
+ /**
32
+ * Renders the Link Wrapper block.
33
+ *
34
+ * @param array $attributes Block attributes.
35
+ * @param string $content Block content.
36
+ * @return string Rendered block HTML.
37
+ */
38
+ function render ( $ attributes , $ content ) {
39
+ $ wrapper_attributes = get_block_wrapper_attributes ();
40
+ $ link = isset ( $ attributes ['url ' ] ) ? ' ' . $ attributes ['url ' ] : get_permalink ();
41
+
42
+ return sprintf (
43
+ '<a href="%1$s" %2$s>%3$s</a> ' ,
44
+ esc_url ( $ link ),
45
+ $ wrapper_attributes ,
46
+ do_blocks ( $ content )
47
+ );
24
48
}
Original file line number Diff line number Diff line change 30
30
"padding" : true
31
31
}
32
32
},
33
+ "dimensions" : {
34
+ "minHeight" : true
35
+ },
33
36
"typography" : {
34
37
"fontSize" : true ,
35
38
"lineHeight" : true
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ function Edit( { attributes, setAttributes } ) {
24
24
< >
25
25
< InspectorControls key = "setting" >
26
26
< PanelBody title = { __ ( 'Link destination' , 'wporg' ) } >
27
+ < p > { __ ( 'Defaults to the permalink if not set.' , 'wporg' ) } </ p >
27
28
< TextControl
28
29
label = { __ ( 'Link destination' , 'wporg' ) }
29
30
hideLabelFromVision
@@ -55,12 +56,7 @@ function Edit( { attributes, setAttributes } ) {
55
56
56
57
registerBlockType ( metadata . name , {
57
58
edit : Edit ,
58
- save : ( { attributes } ) => {
59
- const blockProps = useBlockProps . save ( ) ;
60
- return (
61
- < a { ...blockProps } href = { attributes . url } >
62
- < InnerBlocks . Content />
63
- </ a >
64
- ) ;
59
+ save : ( ) => {
60
+ return < InnerBlocks . Content />
65
61
} ,
66
62
} ) ;
You can’t perform that action at this time.
0 commit comments