block_type_metadata
Filter HookDescription
Ensures backwards compatibility for any users running the Gutenberg plugin who have used Post Comments before it was merged into Comments Query Loop. The same approach was followed when core/query-loop was renamed to core/post-template. / function register_legacy_post_comments_block() { $registry = WP_Block_Type_Registry::get_instance(); /* Remove the old `post-comments` block if it was already registered, as it is about to be replaced by the type defined below. / if ( $registry->is_registered( 'core/post-comments' ) ) { unregister_block_type( 'core/post-comments' ); } // Recreate the legacy block metadata. $metadata = array( 'name' => 'core/post-comments', 'category' => 'theme', 'attributes' => array( 'textAlign' => array( 'type' => 'string', ), ), 'uses_context' => array( 'postId', 'postType', ), 'supports' => array( 'html' => false, 'align' => array( 'wide', 'full' ), 'typography' => array( 'fontSize' => true, 'lineHeight' => true, '__experimentalFontStyle' => true, '__experimentalFontWeight' => true, '__experimentalLetterSpacing' => true, '__experimentalTextTransform' => true, '__experimentalDefaultControls' => array( 'fontSize' => true, ), ), 'color' => array( 'gradients' => true, 'link' => true, '__experimentalDefaultControls' => array( 'background' => true, 'text' => true, ), ), 'inserter' => false, ), 'style' => array( 'wp-block-post-comments', 'wp-block-buttons', 'wp-block-button', ), 'render_callback' => 'render_block_core_comments', 'skip_inner_blocks' => true, ); /* Filters the metadata object, the same way it's done inside `register_block_type_from_metadata()`. This applies some default filters, like `_wp_multiple_block_styles`, which is required in this case because the block has multiple styles.Hook Information
File Location |
wp-includes/blocks/comments.php
View on GitHub
|
Hook Type | Filter |
Line Number | 223 |
Hook Parameters
This hook doesn't accept any parameters.
Usage Examples
Basic Usage
<?php
// Hook into block_type_metadata
add_filter('block_type_metadata', 'my_custom_filter');
function my_custom_filter() {
// Your custom filtering logic here
return 'modified_value';
}
Source Code Context
wp-includes/blocks/comments.php:223
- How this hook is used in WordPress core
<?php
218 * `register_block_type_from_metadata()`. This applies some default filters,
219 * like `_wp_multiple_block_styles`, which is required in this case because
220 * the block has multiple styles.
221 */
222 /** This filter is documented in wp-includes/blocks.php */
223 $metadata = apply_filters( 'block_type_metadata', $metadata );
224
225 register_block_type( 'core/post-comments', $metadata );
226 }
227 add_action( 'init', 'register_legacy_post_comments_block', 21 );
PHP Documentation
<?php
/**
* Ensures backwards compatibility for any users running the Gutenberg plugin
* who have used Post Comments before it was merged into Comments Query Loop.
*
* The same approach was followed when core/query-loop was renamed to
* core/post-template.
*
* @since 6.1.0
*
* @see https://github.com/WordPress/gutenberg/pull/41807
* @see https://github.com/WordPress/gutenberg/pull/32514
*/
function register_legacy_post_comments_block() {
$registry = WP_Block_Type_Registry::get_instance();
/*
* Remove the old `post-comments` block if it was already registered, as it
* is about to be replaced by the type defined below.
*/
if ( $registry->is_registered( 'core/post-comments' ) ) {
unregister_block_type( 'core/post-comments' );
}
// Recreate the legacy block metadata.
$metadata = array(
'name' => 'core/post-comments',
'category' => 'theme',
'attributes' => array(
'textAlign' => array(
'type' => 'string',
),
),
'uses_context' => array(
'postId',
'postType',
),
'supports' => array(
'html' => false,
'align' => array( 'wide', 'full' ),
'typography' => array(
'fontSize' => true,
'lineHeight' => true,
'__experimentalFontStyle' => true,
'__experimentalFontWeight' => true,
'__experimentalLetterSpacing' => true,
'__experimentalTextTransform' => true,
'__experimentalDefaultControls' => array(
'fontSize' => true,
),
),
'color' => array(
'gradients' => true,
'link' => true,
'__experimentalDefaultControls' => array(
'background' => true,
'text' => true,
),
),
'inserter' => false,
),
'style' => array(
'wp-block-post-comments',
'wp-block-buttons',
'wp-block-button',
),
'render_callback' => 'render_block_core_comments',
'skip_inner_blocks' => true,
);
/*
* Filters the metadata object, the same way it's done inside
* `register_block_type_from_metadata()`. This applies some default filters,
* like `_wp_multiple_block_styles`, which is required in this case because
* the block has multiple styles.
*/
Quick Info
- Hook Type: Filter
- Parameters: 0
- File: wp-includes/blocks/comments.php
Related Hooks
Related hooks will be displayed here in future updates.