From 7c1321e81715a21f8af88008b5b614b1ea512af2 Mon Sep 17 00:00:00 2001 From: Chandler Weiner <23106097+crweiner@users.noreply.github.com> Date: Fri, 8 May 2026 17:18:56 -0400 Subject: [PATCH 1/2] Plugins: Add hidden File column to plugin list table --- src/wp-admin/css/list-tables.css | 5 ++ .../includes/class-wp-plugins-list-table.php | 28 +++++++ .../tests/admin/wpPluginsListTable.php | 77 +++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/src/wp-admin/css/list-tables.css b/src/wp-admin/css/list-tables.css index 679cef5854307..4718f5446105e 100644 --- a/src/wp-admin/css/list-tables.css +++ b/src/wp-admin/css/list-tables.css @@ -2292,6 +2292,11 @@ div.action-links, display: table-cell; } + /* Plugin columns hidden via Screen Options */ + #wpbody-content .wp-list-table.plugins td.hidden { + display: none; + } + /* Plugin description hidden via Screen Options */ #wpbody-content .wp-list-table.plugins .desc.hidden { display: none; diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index c4866076f984d..bf7163aade53f 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -60,6 +60,8 @@ public function __construct( $args = array() ) { $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' ) && current_user_can( 'update_plugins' ) && ( ! is_multisite() || $this->screen->in_admin( 'network' ) ); + + add_filter( 'default_hidden_columns', array( $this, 'get_default_hidden_columns' ), 10, 2 ); } /** @@ -476,9 +478,32 @@ public function get_columns() { $columns['auto-updates'] = __( 'Automatic Updates' ); } + $columns['file'] = _x( 'File', 'plugin screen column name' ); + return $columns; } + /** + * Filters the default hidden columns for the plugins list table. + * + * @since n.e.x.t + * + * @param string[] $hidden Array of IDs of columns hidden by default. + * @param WP_Screen $screen WP_Screen object of the current screen. + * @return string[] Array of IDs of columns hidden by default. + */ + public function get_default_hidden_columns( $hidden, $screen ) { + if ( ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) { + return $hidden; + } + + if ( ! in_array( 'file', $hidden, true ) ) { + $hidden[] = 'file'; + } + + return $hidden; + } + /** * @return array */ @@ -1175,6 +1200,9 @@ public function single_row( $item ) { echo $this->row_actions( $actions, true ); echo ''; break; + case 'file': + echo "" . esc_html( $plugin_file ) . ''; + break; case 'description': $classes = 'column-description desc'; diff --git a/tests/phpunit/tests/admin/wpPluginsListTable.php b/tests/phpunit/tests/admin/wpPluginsListTable.php index daa54750fdf9e..5b31fbbe0bdd7 100644 --- a/tests/phpunit/tests/admin/wpPluginsListTable.php +++ b/tests/phpunit/tests/admin/wpPluginsListTable.php @@ -65,6 +65,7 @@ public static function set_up_before_class() { public function set_up() { parent::set_up(); + set_current_screen( 'plugins.php' ); $this->table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => 'plugins' ) ); } @@ -75,6 +76,7 @@ public function tear_down() { global $s; $s = self::$original_s; + set_current_screen( 'front' ); parent::tear_down(); } @@ -120,6 +122,42 @@ public function test_get_views_should_return_views_by_default() { $this->assertSame( $expected, $actual ); } + /** + * Tests that WP_Plugins_List_Table::get_columns() adds the file column. + * + * @ticket 65145 + * + * @covers WP_Plugins_List_Table::get_columns + */ + public function test_get_columns_should_add_the_file_column() { + global $status; + + $original_status = $status; + $status = 'all'; + + $actual = $this->table->get_columns(); + + $status = $original_status; + + $this->assertSame( + array( 'cb', 'name', 'description', 'file' ), + array_keys( $actual ) + ); + } + + /** + * Tests that the file column is hidden by default in Screen Options. + * + * @ticket 65145 + * + * @covers WP_Plugins_List_Table::get_default_hidden_columns + */ + public function test_get_default_hidden_columns_should_hide_the_file_column() { + $hidden = get_hidden_columns( get_current_screen() ); + + $this->assertContains( 'file', $hidden ); + } + /** * Tests that WP_Plugins_List_Table::__construct() does not set * the 'show_autoupdates' property to false for Must-Use and Drop-in @@ -286,6 +324,45 @@ public function test_single_row_should_not_add_the_autoupdates_column_for_mustus $this->assertStringNotContainsString( 'column-auto-updates', $actual, 'The auto-updates column was output.' ); } + /** + * Tests that WP_Plugins_List_Table::single_row() outputs the file column. + * + * @ticket 65145 + * + * @covers WP_Plugins_List_Table::single_row + */ + public function test_single_row_should_output_the_file_column() { + global $status; + + $original_status = $status; + $status = 'all'; + + $column_info = array( + array( + 'name' => 'Plugin', + 'description' => 'Description', + 'file' => 'File', + ), + array(), + array(), + 'name', + ); + + $list_table_mock = $this->getMockBuilder( 'WP_Plugins_List_Table' ) + ->setMethods( array( 'get_column_info' ) ) + ->getMock(); + + $list_table_mock->expects( $this->once() )->method( 'get_column_info' )->willReturn( $column_info ); + + ob_start(); + $list_table_mock->single_row( array( 'fake-plugin.php', $this->fake_plugin['fake-plugin.php'] ) ); + $actual = ob_get_clean(); + + $status = $original_status; + + $this->assertStringContainsString( "fake-plugin.php", $actual ); + } + /** * Data provider. * From 48cc08267791b7cc6cfb9fc21d401f5c15fc85d4 Mon Sep 17 00:00:00 2001 From: Chandler Weiner <23106097+crweiner@users.noreply.github.com> Date: Fri, 8 May 2026 18:16:05 -0400 Subject: [PATCH 2/2] Tests: Use real plugin fixture in plugins list table test --- tests/phpunit/tests/admin/wpPluginsListTable.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/admin/wpPluginsListTable.php b/tests/phpunit/tests/admin/wpPluginsListTable.php index 5b31fbbe0bdd7..d8f9e6c3ca322 100644 --- a/tests/phpunit/tests/admin/wpPluginsListTable.php +++ b/tests/phpunit/tests/admin/wpPluginsListTable.php @@ -336,6 +336,7 @@ public function test_single_row_should_output_the_file_column() { $original_status = $status; $status = 'all'; + $plugins = get_plugins(); $column_info = array( array( @@ -355,12 +356,12 @@ public function test_single_row_should_output_the_file_column() { $list_table_mock->expects( $this->once() )->method( 'get_column_info' )->willReturn( $column_info ); ob_start(); - $list_table_mock->single_row( array( 'fake-plugin.php', $this->fake_plugin['fake-plugin.php'] ) ); + $list_table_mock->single_row( array( 'hello.php', $plugins['hello.php'] ) ); $actual = ob_get_clean(); $status = $original_status; - $this->assertStringContainsString( "fake-plugin.php", $actual ); + $this->assertStringContainsString( "hello.php", $actual ); } /**