From 8f024536c12b66ffc588024c4e6e03d7aadc2b5b Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Tue, 7 Jul 2015 15:11:54 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/class-wp-list-table.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 76fea0096c..9ec1bcee24 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -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; }