Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: column value getting overridden when multiple custom columns are added #1185

Merged
merged 2 commits into from
Jan 5, 2021
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.idea
.DS_Store
/node_modules/
Expand Down
18 changes: 9 additions & 9 deletions classes/class-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,11 @@ public function column_default( $item, $column_name ) {
* Registers new Columns to be inserted into the table. The cell contents of this column is set
* below with 'wp_stream_insert_column_default_'
*
* @param array $new_columns Columns injected in the table.
*
* @return array
*/
$new_columns = array();
$inserted_columns = apply_filters( 'wp_stream_register_column_defaults', $new_columns );
$inserted_columns = apply_filters( 'wp_stream_register_column_defaults', array() );

if ( ! empty( $inserted_columns ) && is_array( $inserted_columns ) ) {
foreach ( $inserted_columns as $column_title ) {
Expand All @@ -404,21 +405,20 @@ public function column_default( $item, $column_name ) {
* Also, note that the action name must include the $column_title registered
* with wp_stream_register_column_defaults
*/
if ( $column_title === $column_name && has_filter( "wp_stream_insert_column_default_{$column_title}" ) ) {
if ( $column_title === $column_name ) {
/**
* Allows for the addition of content under a specified column.
*
* @param object $record Contents of the row
* @param string $out Column content.
* @param object $record Record with row content.
* @param string $column_name Column name.
*
* @return string
*/
$out = apply_filters( "wp_stream_insert_column_default_{$column_title}", $column_name, $record );
} else {
$out = $column_name;
$out = apply_filters( "wp_stream_insert_column_default_{$column_title}", $out, $record, $column_name );
Comment on lines +408 to +418

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this was on the right track, the default filter is never called when creating a key => value pair of column(s).

So when filtering a new column, the $column_title could be Record ID, which is not a filterable value in L418.

Really this should have been:

Suggested change
if ( $column_title === $column_name ) {
/**
* Allows for the addition of content under a specified column.
*
* @param object $record Contents of the row
* @param string $out Column content.
* @param object $record Record with row content.
* @param string $column_name Column name.
*
* @return string
*/
$out = apply_filters( "wp_stream_insert_column_default_{$column_title}", $column_name, $record );
} else {
$out = $column_name;
$out = apply_filters( "wp_stream_insert_column_default_{$column_title}", $out, $record, $column_name );
foreach ( $inserted_columns as $column_key => $column_title ) {
@@ -404,21 +405,20 @@ public function column_default( $item, $column_name ) {
* Also, note that the action name must include the $column_title registered
* with wp_stream_register_column_defaults
*/
if ( $column_title === $column_key ) {
/**
* Allows for the addition of content under a specified column.
*
* @param string $out Column content.
* @param object $record Record with row content.
* @param string $column_name Column name.
*
* @return string
*/
$out = apply_filters( "wp_stream_insert_column_default_{$column_key}", $out, $record, $column_name );

break;
}
}
} else {
$out = $column_name;
}
}

Expand Down
Loading