[wp-trac] [WordPress Trac] #62715: Block Hooks: Apply to content-like Custom Post Types
WordPress Trac
noreply at wordpress.org
Thu Nov 27 18:08:00 UTC 2025
#62715: Block Hooks: Apply to content-like Custom Post Types
-------------------------------------+---------------------
Reporter: Bernhard Reiter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 7.0
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses:
-------------------------------------+---------------------
Comment (by r1k0):
== Test Report
=== Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/9245
=== Environment
- WordPress: 6.9-RC3-61308
- PHP: 8.3.23
- Server: Apache/2.4.43 (Unix)
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.3.23)
- Browser: Firefox 145.0
- OS: Ubuntu
- Theme: Twenty Twenty-Five 1.3
- MU Plugins: None activated
- Plugins:
* Block Hook Test
* Test Reports 1.2.1
=== Actual Results
1. ✅ Issue resolved with patch.
=== Additional Notes
-Create a plugin folder (named:Block Hook Test) and add this code to a
file (named:blockhook.php). Add the plugin in the "wp-content/plugins"
folder and activate the plugin.
{{{
<?php
/**
* Plugin Name: Block Hook Test
* Description: A test plugin to test block hooks for a custom post type
in WordPress.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function blockhooks_test_register_cpt() {
register_post_type( 'book', array(
'labels' => array(
'name' => __('Books'),
'singular_name' => __('Book Item'),
),
'public' => true,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail',
'excerpt', 'comments' ),
'has_archive' => true,
'show_in_menu' => true,
) );
}
add_action( 'init', 'blockhooks_test_register_cpt' );
function blockhooks_test_allow_cpt_for_hooks( $post_types,
$current_post_type, $post ) {
if ( ! in_array( 'book', $post_types, true ) ) {
$post_types[] = 'book';
}
return $post_types;
}
add_filter( 'rest_block_hooks_post_types',
'blockhooks_test_allow_cpt_for_hooks', 10, 3 );
function blockhooks_test_register_block() {
register_block_type('blockhooks-test/added-block', array(
'block_hooks' => array(
'core/post-content' => 'after',
),
'render_callback' => 'blockhooks_test_render_block',
) );
}
add_action( 'init', 'blockhooks_test_register_block' );
function blockhooks_test_render_block( $attributes = array() ) {
$post_type = get_post_type();
$html = '<div class="blockhooks-test-injected"
style="padding:12px;border-left:4px solid #c00;margin:1em
0;background:#eee5e5;">';
$html .= '<strong>Added by Block Hooks:</strong> This block was
inserted automatically by the BlockHooks Test Plugin.';
$html .= '<em style="color:#3410b7">(Post Type: ' . esc_html(
$post_type ) . ')</em>';
$html .= '</div>';
return $html;
}
}}}
- Reset permalinks after activating the plugin.
=== Supplemental Artifacts
Post Type(Post): [[Image(https://i.ibb.co/n54780g/post.png)]]
Custom Post Type(Book): [[Image(https://i.ibb.co/6RTh5q73/book-cpt.png)]]
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62715#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list