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..d8f9e6c3ca322 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,46 @@ 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'; + $plugins = get_plugins(); + + $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( 'hello.php', $plugins['hello.php'] ) ); + $actual = ob_get_clean(); + + $status = $original_status; + + $this->assertStringContainsString( "hello.php", $actual ); + } + /** * Data provider. *