@wordpress/create-block-tutorial-template 2.4.0 → 2.4.1-next.d6164808d3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,7 +20,9 @@ import './editor.scss';
|
|
|
20
20
|
* Internal dependencies
|
|
21
21
|
*/
|
|
22
22
|
import Edit from './edit';
|
|
23
|
+
{{#isStaticVariant}}
|
|
23
24
|
import save from './save';
|
|
25
|
+
{{/isStaticVariant}}
|
|
24
26
|
import metadata from './block.json';
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -41,8 +43,10 @@ registerBlockType( metadata.name, {
|
|
|
41
43
|
* @see ./edit.js
|
|
42
44
|
*/
|
|
43
45
|
edit: Edit,
|
|
46
|
+
{{#isStaticVariant}}
|
|
44
47
|
/**
|
|
45
48
|
* @see ./save.js
|
|
46
49
|
*/
|
|
47
50
|
save,
|
|
51
|
+
{{/isStaticVariant}}
|
|
48
52
|
} );
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
{{#isStaticVariant}}
|
|
1
2
|
/**
|
|
2
3
|
* React hook that is used to mark the block wrapper element.
|
|
3
4
|
* It provides all the necessary props like the class name.
|
|
@@ -21,3 +22,4 @@ export default function save( { attributes } ) {
|
|
|
21
22
|
const blockProps = useBlockProps.save();
|
|
22
23
|
return <div { ...blockProps }>{ attributes.message }</div>;
|
|
23
24
|
}
|
|
25
|
+
{{/isStaticVariant}}
|
package/index.js
CHANGED
|
@@ -22,6 +22,16 @@ module.exports = {
|
|
|
22
22
|
html: false,
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
+
variants: {
|
|
26
|
+
static: {},
|
|
27
|
+
dynamic: {
|
|
28
|
+
attributes: {
|
|
29
|
+
message: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
25
35
|
pluginTemplatesPath: join( __dirname, 'plugin-templates' ),
|
|
26
36
|
blockTemplatesPath: join( __dirname, 'block-templates' ),
|
|
27
37
|
assetsPath: join( __dirname, 'assets' ),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/create-block-tutorial-template",
|
|
3
|
-
"version": "2.4.0",
|
|
3
|
+
"version": "2.4.1-next.d6164808d3.0",
|
|
4
4
|
"description": "Template for @wordpress/create-block used in the official WordPress tutorial.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "ba8a396d2f418e53a6c4c50575582f3f3eb11ff7"
|
|
25
25
|
}
|
|
@@ -37,7 +37,35 @@
|
|
|
37
37
|
*
|
|
38
38
|
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
39
39
|
*/
|
|
40
|
+
{{#isStaticVariant}}
|
|
40
41
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
41
42
|
register_block_type( __DIR__ . '/build' );
|
|
42
43
|
}
|
|
43
44
|
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
45
|
+
{{/isStaticVariant}}
|
|
46
|
+
{{#isDynamicVariant}}
|
|
47
|
+
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
48
|
+
register_block_type(
|
|
49
|
+
__DIR__ . '/build',
|
|
50
|
+
array(
|
|
51
|
+
'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback',
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Render callback function
|
|
59
|
+
*
|
|
60
|
+
* @param array $attributes The block attributes.
|
|
61
|
+
* @param string $content The block content.
|
|
62
|
+
* @param WP_Block $block Block instance.
|
|
63
|
+
*
|
|
64
|
+
* @return string The rendered output.
|
|
65
|
+
*/
|
|
66
|
+
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $atts, $content, $block) {
|
|
67
|
+
ob_start();
|
|
68
|
+
require plugin_dir_path( __FILE__ ) . 'build/template.php';
|
|
69
|
+
return ob_get_clean();
|
|
70
|
+
}
|
|
71
|
+
{{/isDynamicVariant}}
|