Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

Last modified 10 days ago

#64639 closed defect (bug) (fixed)

Allow PHP-Only Block Registration

Reported by: wildworks's profile wildworks Owned by: wildworks's profile wildworks
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch has-unit-tests gutenberg-merge add-to-field-guide needs-dev-note
Focuses: Cc:

Description (last modified by wildworks)

This ticket tracks the backport of PHP files for the following Gutenberg updates:

https://github.com/WordPress/gutenberg/pull/75543

If the supports.auto_register supports.autoRegister flag is opted in when executing register_block_type(), those blocks will be exposed as the autoRegisterBlocks block editor setting.

The editor will use that setting to generate the blocks using server-side rendering.

Change History (10)

This ticket was mentioned in PR #10932 on WordPress/wordpress-develop by @wildworks.


4 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Trac ticket:

## Use of AI Tools

#2 @wildworks
4 weeks ago

  • Keywords gutenberg-merge added

@wildworks commented on PR #10932:


4 weeks ago
#3

@oandregal, Based on your suggestion, I've added server-side type checking in 658b7af6ed40562da9aabaaad86c4b66d1e75525. I'd be happy to see if this is what you wanted.

@oandregal commented on PR #10932:


4 weeks ago
#4

@t-hamano thank you, that's great :)

@wildworks commented on PR #10932:


4 weeks ago
#5

@oandregal Thanks for the review! After committing this PR to core, I would like to backport similar changes to Gutenberg.

#6 @wildworks
4 weeks ago

  • Description modified (diff)

#7 @wildworks
4 weeks ago

  • Owner set to wildworks
  • Resolution set to fixed
  • Status changed from new to closed

In 61661:

Block Supports: Add autoRegister support for PHP-only block registration.

Introduces block support for PHP-only block registration, enabling developers to register blocks in PHP without requiring JavaScript registration code.

When a block declares 'supports' => array( 'autoRegister' => true ) along with a render callback, it is exposed to the client-side via a JavaScript global variable and registered automatically.

Example usage:

register_block_type(
	'my-plugin/example',
	array(
		'title'           => 'My Example Block',
		'attributes'      => array(
			'title' => array(
				'type'    => 'string',
				'default' => 'Hello World',
			),
			'count' => array(
				'type'    => 'integer',
				'default' => 5,
			),
		),
		'render_callback' => function ( $attributes ) {
			return sprintf(
				'<div %1$s>%2$s: %3$d items</div>',
				get_block_wrapper_attributes(),
				esc_html( $attributes['title'] ),
				$attributes['count']
			);
		},
		'supports'        => array(
			'autoRegister' => true,
		),
	)
);

Props mcsf, oandregal, ramonopoly, westonruter, wildworks.
Fixes #64639.

#8 @butterflymedia
11 days ago

This is THE FIRST block-editor-related good news since Gutenberg was first implemented.

This is also a nice, extended, resource of some additional blocks being implemented using this method:

https://getbutterfly.com/php-only-block-registration-in-wordpress/

Last edited 10 days ago by butterflymedia (previous) (diff)

#9 @audrasjb
11 days ago

  • Keywords add-to-field-guide needs-dev-note added

This will need a dedicated dev note.
@wildworks are you gonna handle that task?

And of course it's worth a mention in the Field Guide.

#10 @wildworks
11 days ago

A dev note for this feature is being tracked on the Gutenberg side and has just been published.

https://make.wordpress.org/core/2026/03/03/php-only-block-registration/

Note: See TracTickets for help on using tickets.