Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions classes/class-live-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
4 changes: 2 additions & 2 deletions classes/class-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/test-class-live-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}
}