diff --git a/backport-changelog/6.7/7543.md b/backport-changelog/6.7/7543.md new file mode 100644 index 0000000000000..7dcb74354ac81 --- /dev/null +++ b/backport-changelog/6.7/7543.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/7543 + +* https://github.com/WordPress/gutenberg/pull/65958 diff --git a/lib/compat/wordpress-6.7/block-templates.php b/lib/compat/wordpress-6.7/block-templates.php index d1f2859070b8b..65d99ee978efe 100644 --- a/lib/compat/wordpress-6.7/block-templates.php +++ b/lib/compat/wordpress-6.7/block-templates.php @@ -5,7 +5,7 @@ * @package gutenberg */ -if ( ! function_exists( 'wp_register_block_template' ) ) { +if ( ! function_exists( 'register_block_template' ) ) { /** * Register a template. * @@ -22,20 +22,63 @@ * } * @return WP_Block_Template|WP_Error The registered template object on success, WP_Error object on failure. */ - function wp_register_block_template( $template_name, $args = array() ) { + function register_block_template( $template_name, $args = array() ) { return WP_Block_Templates_Registry::get_instance()->register( $template_name, $args ); } } +if ( ! function_exists( 'unregister_block_template' ) ) { + /** + * Unregister a template. + * + * @param string $template_name Template name in the form of `plugin_uri//template_name`. + * @return WP_Block_Template|WP_Error The unregistered template object on success, WP_Error object on failure or if + * the template doesn't exist. + */ + function unregister_block_template( $template_name ) { + return WP_Block_Templates_Registry::get_instance()->unregister( $template_name ); + } +} + +if ( ! function_exists( 'wp_register_block_template' ) ) { + /** + * Register a template. + * + * @deprecated 19.4.0 wp_register_block_template is deprecated. Please use register_block_template instead. + * + * @param string $template_name Template name in the form of `plugin_uri//template_name`. + * @param array|string $args { + * Optional. Array or string of arguments for registering a block template. + * + * @type string $title Optional. Title of the template as it will be shown in the Site Editor + * and other UI elements. + * @type string $description Optional. Description of the template as it will be shown in the Site + * Editor. + * @type string $content Optional. Default content of the template that will be used when the + * template is rendered or edited in the editor. + * @type string[] $post_types Optional. Array of post types to which the template should be available. + * @type string $plugin Uri of the plugin that registers the template. + * } + * @return WP_Block_Template|WP_Error The registered template object on success, WP_Error object on failure. + */ + function wp_register_block_template( $template_name, $args = array() ) { + _deprecated_function( __FUNCTION__, 'Gutenberg 19.4.0', 'register_block_template' ); + register_block_template( $template_name, $args ); + } +} + if ( ! function_exists( 'wp_unregister_block_template' ) ) { /** * Unregister a template. * + * @deprecated 19.4.0 wp_unregister_block_template is deprecated. Please use unregister_block_template instead. + * * @param string $template_name Template name in the form of `plugin_uri//template_name`. * @return WP_Block_Template|WP_Error The unregistered template object on success, WP_Error object on failure or if * the template doesn't exist. */ function wp_unregister_block_template( $template_name ) { - return WP_Block_Templates_Registry::get_instance()->unregister( $template_name ); + _deprecated_function( __FUNCTION__, 'Gutenberg 19.4.0', 'unregister_block_template' ); + return unregister_block_template( $template_name ); } } diff --git a/packages/e2e-tests/plugins/block-template-registration.php b/packages/e2e-tests/plugins/block-template-registration.php index a7c7555284965..f93deb19688c4 100644 --- a/packages/e2e-tests/plugins/block-template-registration.php +++ b/packages/e2e-tests/plugins/block-template-registration.php @@ -11,7 +11,7 @@ 'init', function () { // Custom template used by most tests. - wp_register_block_template( + register_block_template( 'gutenberg//plugin-template', array( 'title' => 'Plugin Template', @@ -28,7 +28,7 @@ function () { ); // Custom template overridden by the theme. - wp_register_block_template( + register_block_template( 'gutenberg//custom-template', array( 'title' => 'Custom Template (overridden by the theme)', @@ -39,7 +39,7 @@ function () { ); // Custom template used to test unregistration. - wp_register_block_template( + register_block_template( 'gutenberg//plugin-unregistered-template', array( 'title' => 'Plugin Unregistered Template', @@ -47,10 +47,10 @@ function () { 'content' => '

This is a plugin-registered template that is also unregistered.

', ) ); - wp_unregister_block_template( 'gutenberg//plugin-unregistered-template' ); + unregister_block_template( 'gutenberg//plugin-unregistered-template' ); // Custom template used to test overriding default WP templates. - wp_register_block_template( + register_block_template( 'gutenberg//page', array( 'title' => 'Plugin Page Template', @@ -60,7 +60,7 @@ function () { ); // Custom template used to test overriding default WP templates which can be created by the user. - wp_register_block_template( + register_block_template( 'gutenberg//author-admin', array( 'title' => 'Plugin Author Template', diff --git a/phpunit/block-template-test.php b/phpunit/block-template-test.php index 6589aad90b805..d3cfb1fe12f4f 100644 --- a/phpunit/block-template-test.php +++ b/phpunit/block-template-test.php @@ -11,13 +11,13 @@ public function set_up() { public function test_get_block_templates_from_registry() { $template_name = 'test-plugin//test-template'; - wp_register_block_template( $template_name ); + register_block_template( $template_name ); $templates = get_block_templates(); $this->assertArrayHasKey( $template_name, $templates ); - wp_unregister_block_template( $template_name ); + unregister_block_template( $template_name ); } public function test_get_block_template_from_registry() { @@ -26,12 +26,12 @@ public function test_get_block_template_from_registry() { 'title' => 'Test Template', ); - wp_register_block_template( $template_name, $args ); + register_block_template( $template_name, $args ); $template = get_block_template( 'block-theme//test-template' ); $this->assertEquals( 'Test Template', $template->title ); - wp_unregister_block_template( $template_name ); + unregister_block_template( $template_name ); } } diff --git a/phpunit/class-gutenberg-rest-templates-controller-test.php b/phpunit/class-gutenberg-rest-templates-controller-test.php index 14735246c6fb2..b69416c675305 100644 --- a/phpunit/class-gutenberg-rest-templates-controller-test.php +++ b/phpunit/class-gutenberg-rest-templates-controller-test.php @@ -32,7 +32,7 @@ public function test_get_item() { 'post_types' => array( 'post', 'page' ), ); - wp_register_block_template( $template_name, $args ); + register_block_template( $template_name, $args ); $request = new WP_REST_Request( 'GET', '/wp/v2/templates/test-plugin//test-template' ); $response = rest_get_server()->dispatch( $request ); @@ -52,7 +52,7 @@ public function test_get_item() { $this->assertSame( 'Test Template', $data['title']['rendered'], 'Template title mismatch.' ); $this->assertSame( 'test-plugin', $data['plugin'], 'Plugin name mismatch.' ); - wp_unregister_block_template( $template_name ); + unregister_block_template( $template_name ); $request = new WP_REST_Request( 'GET', '/wp/v2/templates/test-plugin//test-template' ); $response = rest_get_server()->dispatch( $request );