From 3439a14e57b1fb6c1b9ecdb7a740a76df1385bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowski?= Date: Thu, 2 Jul 2020 17:20:28 +0000 Subject: [PATCH] Editor: Move core blocks registration to init hook After working on support for register_block_type_args filter in #49615, it became clear that we need to use init action for core blocks to make it possible to use this filter. Fixes #50263. git-svn-id: https://develop.svn.wordpress.org/trunk@48279 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks/index.php | 81 +++++++++++++++------------- tests/phpunit/includes/functions.php | 1 + 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/wp-includes/blocks/index.php b/src/wp-includes/blocks/index.php index 53aaf2756a..d4482718c1 100644 --- a/src/wp-includes/blocks/index.php +++ b/src/wp-includes/blocks/index.php @@ -18,41 +18,50 @@ require ABSPATH . WPINC . '/blocks/shortcode.php'; require ABSPATH . WPINC . '/blocks/social-link.php'; require ABSPATH . WPINC . '/blocks/tag-cloud.php'; -$block_folders = array( - 'audio', - 'button', - 'buttons', - 'classic', - 'code', - 'column', - 'columns', - 'file', - 'gallery', - 'group', - 'heading', - 'html', - 'image', - 'list', - 'media-text', - 'missing', - 'more', - 'nextpage', - 'paragraph', - 'preformatted', - 'pullquote', - 'quote', - 'separator', - 'social-links', - 'spacer', - 'subhead', - 'table', - 'text-columns', - 'verse', - 'video', -); - -foreach ( $block_folders as $block_folder ) { - register_block_type_from_metadata( - ABSPATH . WPINC . '/blocks/' . $block_folder +/** + * Registers core block types using metadata files. + * Dynamic core blocks are registered separately. + * + * @since 5.5.0 + */ +function register_core_block_types_from_metadata() { + $block_folders = array( + 'audio', + 'button', + 'buttons', + 'classic', + 'code', + 'column', + 'columns', + 'file', + 'gallery', + 'group', + 'heading', + 'html', + 'image', + 'list', + 'media-text', + 'missing', + 'more', + 'nextpage', + 'paragraph', + 'preformatted', + 'pullquote', + 'quote', + 'separator', + 'social-links', + 'spacer', + 'subhead', + 'table', + 'text-columns', + 'verse', + 'video', ); + + foreach ( $block_folders as $block_folder ) { + register_block_type_from_metadata( + ABSPATH . WPINC . '/blocks/' . $block_folder + ); + } } +add_action( 'init', 'register_core_block_types_from_metadata' ); diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 4b88b59da3..f0f9db10c3 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -314,5 +314,6 @@ function _unhook_block_registration() { remove_action( 'init', 'register_block_core_social_link' ); remove_action( 'init', 'register_block_core_social_link' ); remove_action( 'init', 'register_block_core_tag_cloud' ); + remove_action( 'init', 'register_core_block_types_from_metadata' ); } tests_add_filter( 'init', '_unhook_block_registration', 1000 );