From 104f697433b9be9002bb2ca44075f9e99936c3f9 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 27 Aug 2026 12:10:13 +0530 Subject: [PATCH] Keep thousands separator in record and site counts --- classes/class-live-update.php | 4 +-- classes/class-network.php | 4 +-- tests/phpunit/test-class-live-update.php | 33 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/classes/class-live-update.php b/classes/class-live-update.php index 00a7a0524..a3e7d1508 100644 --- a/classes/class-live-update.php +++ b/classes/class-live-update.php @@ -197,8 +197,8 @@ public function heartbeat_received( $response, $data ) { if ( isset( $data['wp-stream-heartbeat'] ) && isset( $total_items ) ) { $response['total_items'] = $total_items; - /* translators: %d: number of items (e.g. "42") */ - $response['total_items_i18n'] = sprintf( _n( '%d item', '%d items', $total_items, 'stream' ), number_format_i18n( $total_items ) ); + /* translators: %s: number of items (e.g. "1,234") */ + $response['total_items_i18n'] = sprintf( _n( '%s item', '%s items', $total_items, 'stream' ), number_format_i18n( $total_items ) ); } if ( isset( $data['wp-stream-heartbeat'] ) && 'live-update' === $data['wp-stream-heartbeat'] && $enable_stream_update ) { diff --git a/classes/class-network.php b/classes/class-network.php index 15209145c..4d2e808cd 100644 --- a/classes/class-network.php +++ b/classes/class-network.php @@ -563,8 +563,8 @@ public function network_query_args( $args ) { */ public function network_admin_page_title( $page_title ) { if ( is_network_admin() ) { - /* translators: %d: number of sites on the network (e.g. "42") */ - $site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) ); + /* translators: %s: number of sites on the network (e.g. "1,234") */ + $site_count = sprintf( _n( '%s site', '%s sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) ); $page_title = sprintf( '%s (%s)', $page_title, $site_count ); } diff --git a/tests/phpunit/test-class-live-update.php b/tests/phpunit/test-class-live-update.php index c6195bbaa..4b06a1f36 100644 --- a/tests/phpunit/test-class-live-update.php +++ b/tests/phpunit/test-class-live-update.php @@ -83,4 +83,37 @@ public function test_enable_live_update_denies_users_without_view_cap() { $this->assertSame( 'off', get_user_meta( $user_id, $this->live_update->user_meta_key, true ) ); } + + public function test_heartbeat_item_count_keeps_thousands_separator() { + global $wpdb; + + wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); + $this->plugin->settings->options['general_role_access'] = array( 'administrator' ); + + $values = array(); + for ( $i = 0; $i < 1000; $i++ ) { + $values[] = $wpdb->prepare( + '( 1, %d, 0, 0, %s, %s, %s, %s, %s, %s, %s )', + get_current_blog_id(), + 'administrator', + 'Record ' . $i, + gmdate( 'Y-m-d H:i:s' ), + 'settings', + 'settings', + 'updated', + '127.0.0.1' + ); + } + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery -- Each row is prepared above. + $wpdb->query( "INSERT INTO {$wpdb->stream} ( site_id, blog_id, object_id, user_id, user_role, summary, created, connector, context, action, ip ) VALUES " . implode( ',', $values ) ); + + $response = $this->live_update->heartbeat_received( array(), array( 'wp-stream-heartbeat' => 'live-update' ) ); + + $this->assertGreaterThan( 999, $response['total_items'] ); + $this->assertSame( + sprintf( '%s items', number_format_i18n( $response['total_items'] ) ), + $response['total_items_i18n'] + ); + } }