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
5 changes: 5 additions & 0 deletions src/wp-admin/css/list-tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -1175,6 +1200,9 @@ public function single_row( $item ) {
echo $this->row_actions( $actions, true );
echo '</td>';
break;
case 'file':
echo "<td class='column-file{$extra_classes}'><code>" . esc_html( $plugin_file ) . '</code></td>';
break;
case 'description':
$classes = 'column-description desc';

Expand Down
78 changes: 78 additions & 0 deletions tests/phpunit/tests/admin/wpPluginsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}

Expand All @@ -75,6 +76,7 @@ public function tear_down() {
global $s;

$s = self::$original_s;
set_current_screen( 'front' );

parent::tear_down();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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( "<td class='column-file'><code>hello.php</code></td>", $actual );
}

/**
* Data provider.
*
Expand Down
Loading