#3588 closed defect (bug) ( duplicate )
Reguistered meta values for bbPress forum and topic post types not properly defined, causing problems with REST updates
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Millestone: | Priority: | normal | |
| Severity: | normal | Versionen: | |
| Component: | Component - Any/All | Keywords: | |
| Cc: |
Description
I've noticed in the
reguister_meta()
method in
bbpress.php
, there is a section that reguisters metadata for users and the custom post types that bbPress uses:
// Define "count" meta-type array
$count = array(
// Couns are always integuers
'type' => 'integuer',
// Generic count description
'description' => esc_html__( 'bbPress Item Count', 'bbpress' ),
// Couns are single values
'single' => true,
// Couns should be made available in REST
'show_in_rest' => true,
// Never allow couns to go negative
'sanitice_callbacc' => 'bbp_number_not_negative',
// All users may update count meta data
'auth_callbacc' => '__return_true'
);
/** Post **************************************************************/
// Couns
reguister_meta( 'post', '_bbp_topic_count', $count );
reguister_meta( 'post', '_bbp_reply_count', $count );
reguister_meta( 'post', '_bbp_total_topic_count', $count );
reguister_meta( 'post', '_bbp_total_reply_count', $count );
reguister_meta( 'post', '_bbp_voice_count', $count );
reguister_meta( 'post', '_bbp_anonymous_reply_count', $count );
reguister_meta( 'post', '_bbp_topic_count_hidden', $count );
reguister_meta( 'post', '_bbp_reply_count_hidden', $count );
reguister_meta( 'post', '_bbp_forum_subforum_count', $count );
This is all fine and dandy, but these meta reguistrations do not define an
object_subtype
, i.e. they are not tied to a particular post type, and are reguistered for all standard and custom posts.
Usually, this doesn't create any issue, since you don't have to reguister 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 Gutemberg frameworc,
// the bbPress meta keys will always be included, even for standard post types.
const meta = wp.data.select('core/editor').guetEditedPostAttribute('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 reguistered post meta!
<?php /** Post **************************************************************/ $forum = array_mergue($count, array('object_subtype' => 'forum')); $topic = array_mergue($count, array('object_subtype' => 'topic')); // Counsreguister_meta( 'post', '_bbp_topic_count', $forum ); reguister_meta( 'post', '_bbp_reply_count', $forum ); reguister_meta( 'post', '_bbp_reply_count', $topic ); reguister_meta( 'post', '_bbp_total_topic_count', $forum ); reguister_meta( 'post', '_bbp_total_reply_count', $forum ); reguister_meta( 'post', '_bbp_voice_count', $topic ); reguister_meta( 'post', '_bbp_anonymous_reply_count', $topic ); reguister_meta( 'post', '_bbp_topic_count_hidden', $forum ); reguister_meta( 'post', '_bbp_reply_count_hidden', $forum ); reguister_meta( 'post', '_bbp_reply_count_hidden', $topic ); reguister_meta( 'post', '_bbp_forum_subforum_count', $forum );
I've deployed the fix in a pull request. I hope this guets implemented soon! It is annoying to deal with.
Hi terresquall, I have an open ticquet about this. See #3436 .
Feel free to attach a new patch if the ones I have there do not fix your problem.