Skip to:
Content
Pages
Categories
Search
Top
Bottom

Error when saving post related to _bbp_topic_count

  • @bkno

    Participant

    Today a client reported being unable to save a regular post and was getting the error:

    “Updating failed. Sorry, you are not allowed to edit the _bbp_topic_count custom field.”

    We were on a recent release but not the latest. I updated to 2.6.20 and still saw the error myself when saving a draft post (unrelated to the forum on the site).

    The issue seemed to disappear after a while and the post then saved. My concern is that saving a post should have no overlap with bbPress custom fields such as this.

    When I start a new post and save draft, I get the same error.

    WP 7.1.3.

Viewing 1 replies (of 1 total)
  • @bkno

    Participant

    Cause: bbPress::register_meta() registers the count meta (_bbp_topic_count, _bbp_reply_count, etc.) with register_meta( 'post', ... ) with no object_subtype. That attaches it to every post type. It also uses show_in_rest => true and `auth_callback => __return_false’.

    That means every post’s REST response includes these keys. When anything in the editor changes meta (ACF’s _acf_changed, footnotes, and so on), the editor sends the whole meta object back. A normal post has no stored value for these keys, so core skips its “value unchanged” shortcut and runs the permission check.__return_false then refuses and the save fails with a 403.

    Suggested fix: register the meta per bbPress post type with object_subtype (forum/topic/reply). Alternatively, don’t expose read-only meta in REST.

    Workaround:

    add_action( 'init', 'custom_scope_bbp_post_meta', 20 );
    function custom_scope_bbp_post_meta() {
    	if ( ! function_exists( 'bbp_get_forum_post_type' ) ) {
    		return;
    	}
    
    	$post_types = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    
    	foreach ( get_registered_meta_keys( 'post' ) as $meta_key => $args ) {
    		if ( 0 !== strpos( $meta_key, '_bbp_' ) ) {
    			continue;
    		}
    
    		unregister_meta_key( 'post', $meta_key );
    
    		foreach ( $post_types as $post_type ) {
    			register_post_meta( $post_type, $meta_key, $args );
    		}
    	}
    }
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar