Block Bindings: Fix panel not appearing in custom post types.

There is a bug where the attributes panel is not shown in custom post types. This is caused because each post type can define a capability_type, which by default is post, so the logic to map the capabilities wasn't correct and it was returning false.

Props santosguillamot, cbravobernal.
Fixes #62226.


git-svn-id: https://develop.svn.wordpress.org/trunk@59239 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Carlos Bravo 2024-10-15 14:11:12 +00:00
parent bf2aa81f6e
commit 33b6e1a8bf

View File

@ -825,8 +825,13 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
$caps[] = 'do_not_allow';
break;
}
$caps = map_meta_cap( "edit_{$object_subtype}", $user_id, $object_id );
$post_type_object = get_post_type_object( $object_subtype );
// Initialize empty array if it doesn't exist.
if ( ! isset( $post_type_object->capabilities ) ) {
$post_type_object->capabilities = array();
}
$post_type_capabilities = get_post_type_capabilities( $post_type_object );
$caps = map_meta_cap( $post_type_capabilities->edit_post, $user_id, $object_id );
break;
default:
// Handle meta capabilities for custom post types.