From 3b8cc49b52bd5939a38c57b0e918d17c04835975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 9 Oct 2024 00:28:11 +0200 Subject: [PATCH 1/4] Rename wp_register_block_template() to register_block_template() --- lib/compat/wordpress-6.7/block-templates.php | 4 ++-- .../e2e-tests/plugins/block-template-registration.php | 10 +++++----- phpunit/block-template-test.php | 4 ++-- .../class-gutenberg-rest-templates-controller-test.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/compat/wordpress-6.7/block-templates.php b/lib/compat/wordpress-6.7/block-templates.php index d1f2859070b8b4..633dd785d32af5 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,7 +22,7 @@ * } * @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 ); } } diff --git a/packages/e2e-tests/plugins/block-template-registration.php b/packages/e2e-tests/plugins/block-template-registration.php index a7c75552849658..219e6bdb2d0649 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', @@ -50,7 +50,7 @@ function () { wp_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 6589aad90b8053..5626a5eb103f62 100644 --- a/phpunit/block-template-test.php +++ b/phpunit/block-template-test.php @@ -11,7 +11,7 @@ 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(); @@ -26,7 +26,7 @@ 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' ); diff --git a/phpunit/class-gutenberg-rest-templates-controller-test.php b/phpunit/class-gutenberg-rest-templates-controller-test.php index 14735246c6fb20..f6f952f1ff5ccd 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 ); From af4e452c54aeb8389d1f6ad8b051f4cfd9485b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 9 Oct 2024 00:41:25 +0200 Subject: [PATCH 2/4] Rename wp_unregister_block_template() to unregister_block_template() --- lib/compat/wordpress-6.7/block-templates.php | 4 ++-- packages/e2e-tests/plugins/block-template-registration.php | 2 +- phpunit/block-template-test.php | 4 ++-- phpunit/class-gutenberg-rest-templates-controller-test.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/compat/wordpress-6.7/block-templates.php b/lib/compat/wordpress-6.7/block-templates.php index 633dd785d32af5..97099314cf856b 100644 --- a/lib/compat/wordpress-6.7/block-templates.php +++ b/lib/compat/wordpress-6.7/block-templates.php @@ -27,7 +27,7 @@ function register_block_template( $template_name, $args = array() ) { } } -if ( ! function_exists( 'wp_unregister_block_template' ) ) { +if ( ! function_exists( 'unregister_block_template' ) ) { /** * Unregister a template. * @@ -35,7 +35,7 @@ function register_block_template( $template_name, $args = array() ) { * @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 ) { + function unregister_block_template( $template_name ) { return WP_Block_Templates_Registry::get_instance()->unregister( $template_name ); } } diff --git a/packages/e2e-tests/plugins/block-template-registration.php b/packages/e2e-tests/plugins/block-template-registration.php index 219e6bdb2d0649..f93deb19688c4b 100644 --- a/packages/e2e-tests/plugins/block-template-registration.php +++ b/packages/e2e-tests/plugins/block-template-registration.php @@ -47,7 +47,7 @@ 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. register_block_template( diff --git a/phpunit/block-template-test.php b/phpunit/block-template-test.php index 5626a5eb103f62..d3cfb1fe12f4f5 100644 --- a/phpunit/block-template-test.php +++ b/phpunit/block-template-test.php @@ -17,7 +17,7 @@ public function test_get_block_templates_from_registry() { $this->assertArrayHasKey( $template_name, $templates ); - wp_unregister_block_template( $template_name ); + unregister_block_template( $template_name ); } public function test_get_block_template_from_registry() { @@ -32,6 +32,6 @@ public function test_get_block_template_from_registry() { $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 f6f952f1ff5ccd..b69416c675305b 100644 --- a/phpunit/class-gutenberg-rest-templates-controller-test.php +++ b/phpunit/class-gutenberg-rest-templates-controller-test.php @@ -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 ); From f942c09909d003c74362df6b63ee6739c0a4bff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 9 Oct 2024 00:51:42 +0200 Subject: [PATCH 3/4] Add backport file --- backport-changelog/6.7/7543.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/6.7/7543.md diff --git a/backport-changelog/6.7/7543.md b/backport-changelog/6.7/7543.md new file mode 100644 index 00000000000000..7dcb74354ac813 --- /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 From bcfa70e0b25520025aa7d7814494aeeec6cc67f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 9 Oct 2024 01:26:28 +0200 Subject: [PATCH 4/4] Add back functions with wp_ prefix for backwards compatibility --- lib/compat/wordpress-6.7/block-templates.php | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/compat/wordpress-6.7/block-templates.php b/lib/compat/wordpress-6.7/block-templates.php index 97099314cf856b..65d99ee978efed 100644 --- a/lib/compat/wordpress-6.7/block-templates.php +++ b/lib/compat/wordpress-6.7/block-templates.php @@ -39,3 +39,46 @@ 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 ) { + _deprecated_function( __FUNCTION__, 'Gutenberg 19.4.0', 'unregister_block_template' ); + return unregister_block_template( $template_name ); + } +}