diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 59542a88ffa3dd..cd5fa3082d7d78 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,9 +2,9 @@ version: 2 updates: - # Check for updates to GitHub Actions. - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" - open-pull-requests-limit: 10 + # Check for updates to GitHub Actions. + - package-ecosystem: 'github-actions' + directory: '/' + schedule: + interval: 'daily' + open-pull-requests-limit: 10 diff --git a/docs/reference-guides/block-api/block-metadata.md b/docs/reference-guides/block-api/block-metadata.md index 6ce54d8009dd75..7e1dee9a5f9c29 100644 --- a/docs/reference-guides/block-api/block-metadata.md +++ b/docs/reference-guides/block-api/block-metadata.md @@ -646,7 +646,7 @@ return array( Starting in the WordPress 5.8 release, it is possible to instruct WordPress to enqueue scripts and styles for a block type only when rendered on the frontend. It applies to the following asset fields in the `block.json` file: - `script` -- `viewScript` (when the block defines `render_callback` during registration in PHP or a `render` field in its `block.json`, then the script is registered but the block author is responsible for enqueuing it) +- `viewScript` - `style` ## Internationalization diff --git a/packages/create-block-tutorial-template/CHANGELOG.md b/packages/create-block-tutorial-template/CHANGELOG.md index a61d329b2b85a4..faf6bca521959c 100644 --- a/packages/create-block-tutorial-template/CHANGELOG.md +++ b/packages/create-block-tutorial-template/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancement + +- Update templates to use the `render` field in `block.json` introduced in WordPress 6.1 ([#44185](https://github.com/WordPress/gutenberg/pull/44185)). + ## 2.8.0 (2022-10-19) ## 2.7.0 (2022-10-05) diff --git a/packages/create-block-tutorial-template/block-templates/template.php.mustache b/packages/create-block-tutorial-template/block-templates/render.php.mustache similarity index 100% rename from packages/create-block-tutorial-template/block-templates/template.php.mustache rename to packages/create-block-tutorial-template/block-templates/render.php.mustache diff --git a/packages/create-block-tutorial-template/index.js b/packages/create-block-tutorial-template/index.js index df13ae6100dc2a..514918e70ad8b9 100644 --- a/packages/create-block-tutorial-template/index.js +++ b/packages/create-block-tutorial-template/index.js @@ -30,6 +30,7 @@ module.exports = { type: 'string', }, }, + render: 'file:./render.php', }, }, pluginTemplatesPath: join( __dirname, 'plugin-templates' ), diff --git a/packages/create-block-tutorial-template/plugin-templates/$slug.php.mustache b/packages/create-block-tutorial-template/plugin-templates/$slug.php.mustache index 0211437450c15b..2322881ab0d710 100644 --- a/packages/create-block-tutorial-template/plugin-templates/$slug.php.mustache +++ b/packages/create-block-tutorial-template/plugin-templates/$slug.php.mustache @@ -8,7 +8,7 @@ * Description: {{description}} {{/description}} * Version: {{version}} - * Requires at least: 5.9 + * Requires at least: 6.1 * Requires PHP: 7.0 {{#author}} * Author: {{author}} @@ -38,33 +38,6 @@ * @see https://developer.wordpress.org/reference/functions/register_block_type/ */ function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() { - {{#isStaticVariant}} register_block_type( __DIR__ . '/build' ); - {{/isStaticVariant}} - {{#isDynamicVariant}} - register_block_type( - __DIR__ . '/build', - array( - 'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback', - ) - ); - {{/isDynamicVariant}} } add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' ); -{{#isDynamicVariant}} - -/** - * Render callback function. - * - * @param array $attributes The block attributes. - * @param string $content The block content. - * @param WP_Block $block Block instance. - * - * @return string The rendered output. - */ -function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $atts, $content, $block ) { - ob_start(); - require plugin_dir_path( __FILE__ ) . 'build/template.php'; - return ob_get_clean(); -} -{{/isDynamicVariant}} diff --git a/packages/create-block-tutorial-template/plugin-templates/readme.txt.mustache b/packages/create-block-tutorial-template/plugin-templates/readme.txt.mustache index a8a1de61fc1dec..f069906fb19fa5 100644 --- a/packages/create-block-tutorial-template/plugin-templates/readme.txt.mustache +++ b/packages/create-block-tutorial-template/plugin-templates/readme.txt.mustache @@ -3,7 +3,7 @@ Contributors: {{author}} {{/author}} Tags: block -Tested up to: 6.0 +Tested up to: 6.1 Stable tag: {{version}} {{#license}} License: {{license}} diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index ad798c683b86e4..741b83432200a5 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancement + +- Update templates to use the `render` field in `block.json` introduced in WordPress 6.1 ([#44185](https://github.com/WordPress/gutenberg/pull/44185)). + ## 4.4.0 (2022-10-19) ### New Feature diff --git a/packages/create-block/docs/external-template.md b/packages/create-block/docs/external-template.md index 5eac143a49f1a4..3bbd5a1a06ddf9 100644 --- a/packages/create-block/docs/external-template.md +++ b/packages/create-block/docs/external-template.md @@ -102,4 +102,5 @@ The following configurable variables are used with the template files. Template - `editorScript` (default: `'file:./index.js'`) – an editor script definition. - `editorStyle` (default: `'file:./index.css'`) – an editor style definition. - `style` (default: `'file:./style-index.css'`) – a frontend and editor style definition. +- `render` (no default) – a path to the PHP file used when rendering the block type on the server before presenting on the front end. - `customBlockJSON` (no default) - allows definition of additional properties for the generated block.json file. diff --git a/packages/create-block/lib/init-block.js b/packages/create-block/lib/init-block.js index e8a321f85fed7f..2a83035f9dc6f2 100644 --- a/packages/create-block/lib/init-block.js +++ b/packages/create-block/lib/init-block.js @@ -29,6 +29,7 @@ async function initBlockJSON( { editorScript, editorStyle, style, + render, customBlockJSON, } ) { info( '' ); @@ -57,6 +58,7 @@ async function initBlockJSON( { editorScript, editorStyle, style, + render, ...customBlockJSON, } ).filter( ( [ , value ] ) => !! value ) ), diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index 6f57cdb85a393c..cdeaf85a97bb4a 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -43,6 +43,7 @@ module.exports = async ( editorScript, editorStyle, style, + render, variantVars, customPackageJSON, customBlockJSON, @@ -101,6 +102,7 @@ module.exports = async ( editorScript, editorStyle, style, + render, customPackageJSON, customBlockJSON, ...variantVars, diff --git a/packages/create-block/lib/templates.js b/packages/create-block/lib/templates.js index eb0e5e52631c71..48649527ecc842 100644 --- a/packages/create-block/lib/templates.js +++ b/packages/create-block/lib/templates.js @@ -26,10 +26,13 @@ const predefinedPluginTemplates = { description: 'Example block scaffolded with Create Block tool – no build step required.', dashicon: 'smiley', + supports: { + html: false, + }, wpScripts: false, - editorScript: 'file:./index.js', - editorStyle: 'file:./editor.css', - style: 'file:./style.css', + editorScript: null, + editorStyle: null, + style: null, }, templatesPath: join( __dirname, 'templates', 'es5' ), variants: { @@ -37,6 +40,7 @@ const predefinedPluginTemplates = { dynamic: { slug: 'example-dynamic-es5', title: 'Example Dynamic (ES5)', + render: 'file:./render.php', }, }, }, @@ -55,6 +59,7 @@ const predefinedPluginTemplates = { dynamic: { slug: 'example-dynamic', title: 'Example Dynamic', + render: 'file:./render.php', }, }, }, diff --git a/packages/create-block/lib/templates/block/template.php.mustache b/packages/create-block/lib/templates/block/render.php.mustache similarity index 65% rename from packages/create-block/lib/templates/block/template.php.mustache rename to packages/create-block/lib/templates/block/render.php.mustache index 349a119de8e66d..39ccdaa2b67470 100644 --- a/packages/create-block/lib/templates/block/template.php.mustache +++ b/packages/create-block/lib/templates/block/render.php.mustache @@ -1,5 +1,5 @@ {{#isDynamicVariant}}

> - +

{{/isDynamicVariant}} diff --git a/packages/create-block/lib/templates/es5/$slug.php.mustache b/packages/create-block/lib/templates/es5/$slug.php.mustache index d35db3dea0da45..a04553af1e7d8b 100644 --- a/packages/create-block/lib/templates/es5/$slug.php.mustache +++ b/packages/create-block/lib/templates/es5/$slug.php.mustache @@ -7,7 +7,7 @@ {{#description}} * Description: {{description}} {{/description}} - * Requires at least: 5.7 + * Requires at least: 6.1 * Requires PHP: 7.0 * Version: {{version}} {{#author}} @@ -70,32 +70,12 @@ function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() { ); register_block_type( - '{{namespace}}/{{slug}}', + $dir, array( 'editor_script' => '{{namespace}}-{{slug}}-block-editor', 'editor_style' => '{{namespace}}-{{slug}}-block-editor', 'style' => '{{namespace}}-{{slug}}-block', - {{#isDynamicVariant}} - 'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback', - {{/isDynamicVariant}} ) ); } add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' ); -{{#isDynamicVariant}} - -/** - * Render callback function. - * - * @param array $attributes The block attributes. - * @param string $content The block content. - * @param WP_Block $block Block instance. - * - * @return string The rendered output. - */ -function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $attributes, $content, $block ) { - ob_start(); - require plugin_dir_path( __FILE__ ) . '/template.php'; - return ob_get_clean(); -} -{{/isDynamicVariant}} diff --git a/packages/create-block/lib/templates/es5/index.js.mustache b/packages/create-block/lib/templates/es5/index.js.mustache index 333bd5790b20b0..9738885ac87421 100644 --- a/packages/create-block/lib/templates/es5/index.js.mustache +++ b/packages/create-block/lib/templates/es5/index.js.mustache @@ -33,53 +33,6 @@ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ */ registerBlockType( '{{namespace}}/{{slug}}', { - /** - * @see https://make.wordpress.org/core/2020/11/18/block-api-version-2/ - */ - apiVersion: {{apiVersion}}, - - /** - * This is the display title for your block, which can be translated with `i18n` functions. - * The block inserter will show this name. - */ - title: __( - '{{title}}', - '{{textdomain}}' - ), - - {{#description}} - /** - * This is a short description for your block, can be translated with `i18n` functions. - * It will be shown in the Block Tab in the Settings Sidebar. - */ - description: __( - '{{description}}', - '{{textdomain}}' - ), - - {{/description}} - /** - * Blocks are grouped into categories to help users browse and discover them. - * The categories provided by core are `text`, `media`, `design`, `widgets`, and `embed`. - */ - category: '{{category}}', - - {{#dashicon}} - /** - * An icon property should be specified to make it easier to identify a block. - * These can be any of WordPress’ Dashicons, or a custom svg element. - */ - icon: '{{dashicon}}', - - {{/dashicon}} - /** - * Optional block extended support features. - */ - supports: { - // Removes support for an HTML mode. - html: false, - }, - /** * The edit function describes the structure of your block in the context of the editor. * This represents what the editor will render when the block is used. diff --git a/packages/create-block/lib/templates/es5/readme.txt.mustache b/packages/create-block/lib/templates/es5/readme.txt.mustache index 81ccaf4cb9598a..f069906fb19fa5 100644 --- a/packages/create-block/lib/templates/es5/readme.txt.mustache +++ b/packages/create-block/lib/templates/es5/readme.txt.mustache @@ -3,7 +3,7 @@ Contributors: {{author}} {{/author}} Tags: block -Tested up to: 5.9 +Tested up to: 6.1 Stable tag: {{version}} {{#license}} License: {{license}} diff --git a/packages/create-block/lib/templates/es5/template.php.mustache b/packages/create-block/lib/templates/es5/render.php.mustache similarity index 65% rename from packages/create-block/lib/templates/es5/template.php.mustache rename to packages/create-block/lib/templates/es5/render.php.mustache index 349a119de8e66d..39ccdaa2b67470 100644 --- a/packages/create-block/lib/templates/es5/template.php.mustache +++ b/packages/create-block/lib/templates/es5/render.php.mustache @@ -1,5 +1,5 @@ {{#isDynamicVariant}}

> - +

{{/isDynamicVariant}} diff --git a/packages/create-block/lib/templates/plugin/$slug.php.mustache b/packages/create-block/lib/templates/plugin/$slug.php.mustache index f10318db7ee55f..2ed0354314cc47 100644 --- a/packages/create-block/lib/templates/plugin/$slug.php.mustache +++ b/packages/create-block/lib/templates/plugin/$slug.php.mustache @@ -7,7 +7,7 @@ {{#description}} * Description: {{description}} {{/description}} - * Requires at least: 5.9 + * Requires at least: 6.1 * Requires PHP: 7.0 * Version: {{version}} {{#author}} @@ -38,33 +38,6 @@ * @see https://developer.wordpress.org/reference/functions/register_block_type/ */ function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() { - {{#isStaticVariant}} register_block_type( __DIR__ . '/build' ); - {{/isStaticVariant}} - {{#isDynamicVariant}} - register_block_type( - __DIR__ . '/build', - array( - 'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback', - ) - ); - {{/isDynamicVariant}} } add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' ); -{{#isDynamicVariant}} - -/** - * Render callback function. - * - * @param array $attributes The block attributes. - * @param string $content The block content. - * @param WP_Block $block Block instance. - * - * @return string The rendered output. - */ -function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $attributes, $content, $block ) { - ob_start(); - require plugin_dir_path( __FILE__ ) . 'build/template.php'; - return ob_get_clean(); -} -{{/isDynamicVariant}} diff --git a/packages/create-block/lib/templates/plugin/readme.txt.mustache b/packages/create-block/lib/templates/plugin/readme.txt.mustache index a8a1de61fc1dec..f069906fb19fa5 100644 --- a/packages/create-block/lib/templates/plugin/readme.txt.mustache +++ b/packages/create-block/lib/templates/plugin/readme.txt.mustache @@ -3,7 +3,7 @@ Contributors: {{author}} {{/author}} Tags: block -Tested up to: 6.0 +Tested up to: 6.1 Stable tag: {{version}} {{#license}} License: {{license}}