List tables: Add a fallback for the primary column.

Without a primary column defined, nothing shows in the responsive view at all, which is bad.

props mordauk.
see #25408.


git-svn-id: https://develop.svn.wordpress.org/trunk@33104 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Helen Hou-Sandi 2015-07-07 15:11:54 +00:00
parent 70ab756043
commit 8f024536c1
1 changed files with 16 additions and 2 deletions

View File

@ -832,7 +832,21 @@ class WP_List_Table {
* @return string Name of the default primary column, in this case, an empty string.
*/
protected function get_default_primary_column_name() {
return '';
$columns = $this->get_columns();
$column = '';
// We need a primary defined so responsive views show something,
// so let's fall back to the first non-checkbox column.
foreach( $columns as $col => $column_name ) {
if ( 'cb' === $col ) {
continue;
}
$column = $col;
break;
}
return $column;
}
/**
@ -878,7 +892,7 @@ class WP_List_Table {
if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
// Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
// In 4.3, we added a fourth argument for primary column.
$column_headers = array( array(), array(), array(), '' );
$column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
foreach ( $this->_column_headers as $key => $value ) {
$column_headers[ $key ] = $value;
}