Skip to:
Content
Pages
Categories
Search
Top
Bottom

Fatal error on topic edit screen when a topic has 1,000+ replies

  • @chefranov

    Participant

    Opening a topic for editing in wp-admin (post.php?post=ID&action=edit) fails with a fatal error if the topic has 1,000 or more replies. The “Replies” meta box does not render, and the rest of the edit screen is cut off at that point.

    Environment

    • bbPress 2.6.19
    • WordPress 7.1.2
    • PHP 8.2

    Error

    Uncaught TypeError: number_format(): Argument #1 ($num) must be of type int|float, string given
    in wp-includes/functions.php:428
    
    #0 number_format('2,503', 0, ',', ' ')                    wp-includes/functions.php:428
    #1 number_format_i18n('2,503')                            wp-admin/includes/class-wp-list-table.php:1051
    #2 WP_List_Table->pagination('top')                       bbpress/includes/admin/classes/class-bbp-topic-replies-list-table.php:314
    #3 BBP_Topic_Replies_List_Table->display_tablenav('top')  ...:272
    #4 BBP_Topic_Replies_List_Table->display()                bbpress/includes/admin/metaboxes.php:641
    #5 bbp_topic_replies_metabox(WP_Post, array)

    Cause

    In BBP_Topic_Replies_List_Table::prepare_items() (includes/admin/classes/class-bbp-topic-replies-list-table.php, around line 237), the total is read without the $integer flag:

    $total_items = bbp_get_topic_reply_count( $topic_id );

    Without $integer = true, the value passes through the bbp_get_topic_reply_count filter. bbp_number_format is hooked to that filter in includes/core/filters.php, so it returns a formatted string such as '2,503'. That string then goes into set_pagination_args():

    • WP_List_Table::pagination() calls number_format_i18n( $total_items ). On PHP 8 this throws a TypeError for a non-numeric string.
    • ceil( $total_items / $per_page ) is also wrong. '2,503' / 5 is evaluated as 2 / 5, so total_pages would be 1 even on PHP 7.

    Topics with fewer than 1,000 replies are not affected, because their counts have no thousands separator.

    Steps to reproduce

    1. On PHP 8.x, have a topic with 1,000 or more replies (_bbp_reply_count ≥ 1000).
    2. Open that topic in wp-admin → Topics → Edit.
    3. The “Replies” meta box shows the fatal error above.

    Suggested fix

    Request the integer count:

    $total_items = bbp_get_topic_reply_count( $topic_id, true );

    Workaround (until fixed; restricted to the topic edit screen):

    add_action( 'load-post.php', function () {
        if ( ( $GLOBALS['typenow'] ?? '' ) !== bbp_get_topic_post_type() ) {
            return;
        }
        // Runs after bbp_number_format (priority 10) and strips the separator.
        add_filter( 'bbp_get_topic_reply_count', function ( $count ) {
            return (int) preg_replace( '/\D+/', '', (string) $count );
        }, 20 );
    } );
  • You must be logged in to reply to this topic.
Skip to toolbar