I've noticed in the register_meta() method in bbpress.php, there is a section that registers metadata for users and the custom post types that bbPress uses:
// Define "count" meta-type array
$count = array(
// Counts are always integers
'type' => 'integer',
// Generic count description
'description' => esc_html__( 'bbPress Item Count', 'bbpress' ),
// Counts are single values
'single' => true,
// Counts should be made available in REST
'show_in_rest' => true,
// Never allow counts to go negative
'sanitize_callback' => 'bbp_number_not_negative',
// All users may update count meta data
'auth_callback' => '__return_true'
);
/** Post **************************************************************/
// Counts
register_meta( 'post', '_bbp_topic_count', $count );
register_meta( 'post', '_bbp_reply_count', $count );
register_meta( 'post', '_bbp_total_topic_count', $count );
register_meta( 'post', '_bbp_total_reply_count', $count );
register_meta( 'post', '_bbp_voice_count', $count );
register_meta( 'post', '_bbp_anonymous_reply_count', $count );
register_meta( 'post', '_bbp_topic_count_hidden', $count );
register_meta( 'post', '_bbp_reply_count_hidden', $count );
register_meta( 'post', '_bbp_forum_subforum_count', $count );
This is all fine and dandy, but these meta registrations do not define an object_subtype, i.e. they are not tied to a particular post type, and are registered for all standard and custom posts.
Usually, this doesn't create any issue, since you don't have to register metadata to use them. But if you were to retrieve the metadata of any post in REST, the data will always be included with the post's metadata, regardless of whether the post is actually a bbPress Forum / Topic or not.
// When retrieving post data from WordPress's Gutenberg framework,
// the bbPress meta keys will always be included, even for standard post types.
const meta = wp.data.select('core/editor').getEditedPostAttribute('meta');
Clearly, this is an inconvenience because you will then have to strip the meta values of these unrelated bbPress meta values before you save them.
The fix is simple! Just attach a post type to all registered post meta!
<?php
/** Post **************************************************************/
$forum = array_merge ( $count , array ( 'object_subtype' => 'forum' ));
$topic = array_merge ( $count , array ( 'object_subtype' => 'topic' ));
// Counts
register_meta ( 'post' , '_bbp_topic_count' , $forum );
register_meta ( 'post' , '_bbp_reply_count' , $forum );
register_meta ( 'post' , '_bbp_reply_count' , $topic );
register_meta ( 'post' , '_bbp_total_topic_count' , $forum );
register_meta ( 'post' , '_bbp_total_reply_count' , $forum );
register_meta ( 'post' , '_bbp_voice_count' , $topic );
register_meta ( 'post' , '_bbp_anonymous_reply_count' , $topic );
register_meta ( 'post' , '_bbp_topic_count_hidden' , $forum );
register_meta ( 'post' , '_bbp_reply_count_hidden' , $forum );
register_meta ( 'post' , '_bbp_reply_count_hidden' , $topic );
register_meta ( 'post' , '_bbp_forum_subforum_count' , $forum );
I've deployed the fix in a pull request. I hope this gets implemented soon! It is annoying to deal with.