Skip to content

Commit 0d4a0ee

Browse files
committed
Networks and Sites: Remove view modes from the Network Sites and Users list tables.
The list and excerpt modes on these screens differ only by timestamps and optional site title and tagline output. Remove both view switchers and their request handling, and stop reading and writing the related user settings. Use the former excerpt-mode date format as the canonical display. Remove the site title and tagline output to avoid additional per-row option reads. Update the screen help text and add focused multisite tests. Developed in WordPress#13120. Props afercia, johnjamesjacoby, realloc, sukhendu2002. Fixes #43899. git-svn-id: https://develop.svn.wordpress.org/trunk@65160 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 15e95f3 commit 0d4a0ee

6 files changed

Lines changed: 116 additions & 105 deletions

File tree

‎src/wp-admin/includes/class-wp-ms-sites-list-table.php‎

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,11 @@ public function ajax_user_can() {
6565
*
6666
* @since 3.1.0
6767
*
68-
* @global string $mode List table view mode.
6968
* @global string $s Search string.
7069
* @global wpdb $wpdb WordPress database abstraction object.
7170
*/
7271
public function prepare_items() {
73-
global $mode, $s, $wpdb;
74-
75-
if ( ! empty( $_REQUEST['mode'] ) ) {
76-
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
77-
set_user_setting( 'sites_list_mode', $mode );
78-
} else {
79-
$mode = get_user_setting( 'sites_list_mode', 'list' );
80-
}
72+
global $s, $wpdb;
8173

8274
$per_page = $this->get_items_per_page( 'sites_network_per_page' );
8375

@@ -310,27 +302,6 @@ protected function get_bulk_actions() {
310302
return $actions;
311303
}
312304

313-
/**
314-
* Displays the pagination.
315-
*
316-
* @since 3.1.0
317-
*
318-
* @global string $mode List table view mode.
319-
*
320-
* @param string $which The location of the pagination nav markup: Either 'top' or 'bottom'.
321-
*
322-
* @phpstan-param 'top'|'bottom' $which
323-
*/
324-
protected function pagination( $which ) {
325-
global $mode;
326-
327-
parent::pagination( $which );
328-
329-
if ( 'top' === $which ) {
330-
$this->view_switcher( $mode );
331-
}
332-
}
333-
334305
/**
335306
* Displays extra controls between bulk actions and pagination.
336307
*
@@ -474,13 +445,9 @@ public function column_id( $blog ) {
474445
*
475446
* @since 4.3.0
476447
*
477-
* @global string $mode List table view mode.
478-
*
479448
* @param array $blog Current site.
480449
*/
481450
public function column_blogname( $blog ) {
482-
global $mode;
483-
484451
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
485452

486453
?>
@@ -496,37 +463,17 @@ public function column_blogname( $blog ) {
496463
?>
497464
</strong>
498465
<?php
499-
if ( 'list' !== $mode ) {
500-
switch_to_blog( $blog['blog_id'] );
501-
echo '<p>';
502-
printf(
503-
/* translators: 1: Site title, 2: Site tagline. */
504-
__( '%1$s &#8211; %2$s' ),
505-
get_option( 'blogname' ),
506-
'<em>' . get_option( 'blogdescription' ) . '</em>'
507-
);
508-
echo '</p>';
509-
restore_current_blog();
510-
}
511466
}
512467

513468
/**
514469
* Handles the lastupdated column output.
515470
*
516471
* @since 4.3.0
517472
*
518-
* @global string $mode List table view mode.
519-
*
520473
* @param array $blog Current site.
521474
*/
522475
public function column_lastupdated( $blog ) {
523-
global $mode;
524-
525-
if ( 'list' === $mode ) {
526-
$date = __( 'Y/m/d' );
527-
} else {
528-
$date = __( 'Y/m/d g:i:s a' );
529-
}
476+
$date = __( 'Y/m/d g:i:s a' );
530477

531478
if ( '0000-00-00 00:00:00' === $blog['last_updated'] ) {
532479
_e( 'Never' );
@@ -540,18 +487,10 @@ public function column_lastupdated( $blog ) {
540487
*
541488
* @since 4.3.0
542489
*
543-
* @global string $mode List table view mode.
544-
*
545490
* @param array $blog Current site.
546491
*/
547492
public function column_registered( $blog ) {
548-
global $mode;
549-
550-
if ( 'list' === $mode ) {
551-
$date = __( 'Y/m/d' );
552-
} else {
553-
$date = __( 'Y/m/d g:i:s a' );
554-
}
493+
$date = __( 'Y/m/d g:i:s a' );
555494

556495
if ( '0000-00-00 00:00:00' === $blog['registered'] ) {
557496
echo '&#x2014;';

‎src/wp-admin/includes/class-wp-ms-users-list-table.php‎

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,11 @@ public function ajax_user_can() {
3131
*
3232
* @since 3.1.0
3333
*
34-
* @global string $mode List table view mode.
3534
* @global string $usersearch User search query.
3635
* @global string $role The user role to filter by. Only 'super' (super admins) is supported.
3736
*/
3837
public function prepare_items() {
39-
global $mode, $usersearch, $role;
40-
41-
if ( ! empty( $_REQUEST['mode'] ) ) {
42-
$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
43-
set_user_setting( 'network_users_list_mode', $mode );
44-
} else {
45-
$mode = get_user_setting( 'network_users_list_mode', 'list' );
46-
}
38+
global $usersearch, $role;
4739

4840
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
4941

@@ -189,27 +181,6 @@ protected function get_views() {
189181
return $this->get_views_links( $role_links );
190182
}
191183

192-
/**
193-
* Generates the list table pagination.
194-
*
195-
* @since 3.1.0
196-
*
197-
* @global string $mode List table view mode.
198-
*
199-
* @param string $which The location of the pagination: Either 'top' or 'bottom'.
200-
*
201-
* @phpstan-param 'top'|'bottom' $which
202-
*/
203-
protected function pagination( $which ) {
204-
global $mode;
205-
206-
parent::pagination( $which );
207-
208-
if ( 'top' === $which ) {
209-
$this->view_switcher( $mode );
210-
}
211-
}
212-
213184
/**
214185
* Gets the list of columns for the users list table.
215186
*
@@ -370,18 +341,10 @@ public function column_email( $user ) {
370341
*
371342
* @since 4.3.0
372343
*
373-
* @global string $mode List table view mode.
374-
*
375344
* @param WP_User $user The current WP_User object.
376345
*/
377346
public function column_registered( $user ) {
378-
global $mode;
379-
if ( 'list' === $mode ) {
380-
$date = __( 'Y/m/d' );
381-
} else {
382-
$date = __( 'Y/m/d g:i:s a' );
383-
}
384-
echo mysql2date( $date, $user->user_registered );
347+
echo mysql2date( __( 'Y/m/d g:i:s a' ), $user->user_registered );
385348
}
386349

387350
/**

‎src/wp-admin/network/sites.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'title' => __( 'Overview' ),
3030
'content' =>
3131
'<p>' . __( 'Add Site takes you to the screen for adding a new site to the network. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.' ) . '</p>' .
32-
'<p>' . __( 'This is the main table of all sites on this network. Switch between list and excerpt views by using the icons above the right side of the table.' ) . '</p>' .
32+
'<p>' . __( 'This is the main table of all sites on this network.' ) . '</p>' .
3333
'<p>' . __( 'Hovering over each site reveals seven options (three for the primary site):' ) . '</p>' .
3434
'<ul><li>' . __( 'An Edit link to a separate Edit Site screen.' ) . '</li>' .
3535
'<li>' . __( 'Dashboard leads to the Dashboard for that site.' ) . '</li>' .

‎src/wp-admin/network/users.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
'<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' .
287287
'<p>' . __( 'Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.' ) . '</p>' .
288288
'<p>' . __( 'You can also go to the user&#8217;s profile page by clicking on the individual username.' ) . '</p>' .
289-
'<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
289+
'<p>' . __( 'You can sort the table by clicking on any of the table headings.' ) . '</p>' .
290290
'<p>' . __( 'The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.' ) . '</p>' .
291291
'<p>' . __( 'You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.' ) . '</p>',
292292
)

‎tests/phpunit/tests/multisite/wpMsSitesListTable.php‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,79 @@ public function test_get_views_should_return_views_by_default() {
242242

243243
$this->assertSame( $expected, $this->table->get_views() );
244244
}
245+
246+
/**
247+
* @ticket 43899
248+
*/
249+
public function test_view_switcher_is_not_displayed() {
250+
$pagination = new ReflectionMethod( $this->table, 'pagination' );
251+
if ( PHP_VERSION_ID < 80100 ) {
252+
$pagination->setAccessible( true );
253+
}
254+
255+
ob_start();
256+
$pagination->invoke( $this->table, 'top' );
257+
$output = ob_get_clean();
258+
259+
$this->assertStringNotContainsString( 'view-switch', $output );
260+
}
261+
262+
/**
263+
* @ticket 43899
264+
*/
265+
public function test_site_details_are_not_displayed_without_switching_blog() {
266+
$_REQUEST['mode'] = 'excerpt';
267+
$this->table->prepare_items();
268+
unset( $_REQUEST['mode'] );
269+
270+
$site_id = self::$site_ids['wordpress.org/foo/'];
271+
update_blog_option( $site_id, 'blogname', 'Test site title' );
272+
update_blog_option( $site_id, 'blogdescription', 'Test site tagline' );
273+
274+
$switch_blog = new MockAction();
275+
add_action( 'switch_blog', array( $switch_blog, 'action' ) );
276+
277+
ob_start();
278+
$this->table->column_blogname(
279+
array(
280+
'blog_id' => $site_id,
281+
'domain' => 'wordpress.org',
282+
'path' => '/foo/',
283+
)
284+
);
285+
$output = ob_get_clean();
286+
287+
remove_action( 'switch_blog', array( $switch_blog, 'action' ) );
288+
289+
$this->assertStringNotContainsString( 'Test site title', $output );
290+
$this->assertStringNotContainsString( 'Test site tagline', $output );
291+
$this->assertSame( 0, $switch_blog->get_call_count() );
292+
}
293+
294+
/**
295+
* @ticket 43899
296+
*/
297+
public function test_list_mode_request_does_not_change_site_date_format() {
298+
$_REQUEST['mode'] = 'list';
299+
$this->table->prepare_items();
300+
unset( $_REQUEST['mode'] );
301+
302+
$date = '2025-01-02 03:04:05';
303+
$blog = array(
304+
'last_updated' => $date,
305+
'registered' => $date,
306+
);
307+
308+
ob_start();
309+
$this->table->column_lastupdated( $blog );
310+
$last_updated = ob_get_clean();
311+
312+
ob_start();
313+
$this->table->column_registered( $blog );
314+
$registered = ob_get_clean();
315+
316+
$expected = mysql2date( __( 'Y/m/d g:i:s a' ), $date );
317+
$this->assertSame( $expected, $last_updated );
318+
$this->assertSame( $expected, $registered );
319+
}
245320
}

‎tests/phpunit/tests/multisite/wpMsUsersListTable.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,38 @@ public function test_get_views_should_return_views_by_default() {
104104

105105
$this->assertSame( $expected, $this->table->get_views() );
106106
}
107+
108+
/**
109+
* @ticket 43899
110+
*/
111+
public function test_view_switcher_is_not_displayed() {
112+
$pagination = new ReflectionMethod( $this->table, 'pagination' );
113+
if ( PHP_VERSION_ID < 80100 ) {
114+
$pagination->setAccessible( true );
115+
}
116+
117+
ob_start();
118+
$pagination->invoke( $this->table, 'top' );
119+
$output = ob_get_clean();
120+
121+
$this->assertStringNotContainsString( 'view-switch', $output );
122+
}
123+
124+
/**
125+
* @ticket 43899
126+
*/
127+
public function test_list_mode_request_does_not_change_registered_date_format() {
128+
$_REQUEST['mode'] = 'list';
129+
$this->table->prepare_items();
130+
unset( $_REQUEST['mode'] );
131+
132+
$user = new WP_User();
133+
$user->user_registered = '2025-01-02 03:04:05';
134+
135+
ob_start();
136+
$this->table->column_registered( $user );
137+
$output = ob_get_clean();
138+
139+
$this->assertSame( mysql2date( __( 'Y/m/d g:i:s a' ), $user->user_registered ), $output );
140+
}
107141
}

0 commit comments

Comments
 (0)