[wp-trac] [WordPress Trac] #62715: Block Hooks: Apply to content-like Custom Post Types
WordPress Trac
noreply at wordpress.org
Fri Aug 1 16:27:53 UTC 2025
#62715: Block Hooks: Apply to content-like Custom Post Types
-------------------------------------+---------------------
Reporter: Bernhard Reiter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.9
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses:
-------------------------------------+---------------------
Comment (by iamadisingh):
== 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-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.3
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 138.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
* Test Block Hooks
* Test Reports
=== Actual Results
1. ✅ Issue resolved with patch.
=== Additional Notes
- Added this plugin for registering a new cpt and registered block with
block_hooks
{{{#!php
<?php
/**
* Plugin Name: Test Block Hooks
* Description: Tests Block Hooks
*/
function register_test_cpt() {
register_post_type('portfolio', array(
'labels' => array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio Item',
),
'public' => true,
'show_in_rest' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
));
}
add_action('init', 'register_test_cpt');
function register_test_hooked_block() {
register_block_type('test/social-share', array(
'block_hooks' => array(
'core/post-content' => 'after', // Hook after post content
),
'render_callback' => function($attributes, $content, $block) {
return '<div class="social-share" style="background: #f0f0f0;
padding: 10px; margin: 10px 0;">
🔗 <strong>Share this content!</strong>
<small>(Hooked Block - Post Type: ' . get_post_type() .
')</small>
</div>';
},
));
}
add_action('init', 'register_test_hooked_block');
function test_custom_block_hooks_filter($post_types, $current_post_type,
$post) {
error_log('Block Hooks Filter Called: ' . $current_post_type . ' -
Post Types: ' . implode(', ', $post_types));
if (!in_array('portfolio', $post_types)) {
$post_types[] = 'portfolio';
}
return $post_types;
}
add_filter('rest_block_hooks_post_types',
'test_custom_block_hooks_filter', 10, 3);
}}}
=== Supplemental Artifacts
Default Posts: https://ibb.co/zVNDhVDP
New CPT: https://ibb.co/HkMt7nH
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62715#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list