Fatal error on topic edit screen when a topic has 1,000+ replies
-
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$integerflag:$total_items = bbp_get_topic_reply_count( $topic_id );
Without
$integer = true, the value passes through thebbp_get_topic_reply_countfilter.bbp_number_formatis hooked to that filter inincludes/core/filters.php, so it returns a formatted string such as'2,503'. That string then goes intoset_pagination_args():WP_List_Table::pagination()callsnumber_format_i18n( $total_items ). On PHP 8 this throws aTypeErrorfor a non-numeric string.ceil( $total_items / $per_page )is also wrong.'2,503' / 5is evaluated as2 / 5, sototal_pageswould 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
- On PHP 8.x, have a topic with 1,000 or more replies (
_bbp_reply_count≥ 1000). - Open that topic in wp-admin → Topics → Edit.
- 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.