Skip to content

Commit 2987feb

Browse files
authored
Merge pull request #189 from Automattic/fix/51-row-actions-first-column
2 parents 051f3b5 + 53a731f commit 2987feb

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/class-acm-wp-list-table.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,50 @@ function column_default( $item, $column_name ) {
169169
case 'operator':
170170
return ( ! empty( $item['operator'] ) ) ? $item['operator'] : $ad_code_manager->logical_operator;
171171
default:
172-
// @todo need to make the first column (whatever it is filtered) to show row actions
173-
// Handle custom columns, if any
172+
// Handle custom columns, if any.
174173
if ( isset( $item['url_vars'][ $column_name ] ) ) {
175-
return esc_html( $item['url_vars'][ $column_name ] );
174+
$output = esc_html( $item['url_vars'][ $column_name ] );
175+
176+
// Add row actions to the first data column (after cb and id).
177+
if ( $this->is_first_data_column( $column_name ) ) {
178+
$output .= $this->row_actions_output( $item );
179+
}
180+
181+
return $output;
176182
}
177183
break;
178184
}
179185
}
180186

187+
/**
188+
* Check if the given column is the first data column.
189+
*
190+
* The first data column is the first column after 'cb' (checkbox) and 'id' (hidden).
191+
* This column should display the row actions (edit/delete links).
192+
*
193+
* @since 0.8.0
194+
*
195+
* @param string $column_name The column name to check.
196+
* @return bool True if this is the first data column, false otherwise.
197+
*/
198+
protected function is_first_data_column( $column_name ) {
199+
$columns = $this->get_columns();
200+
201+
// Skip 'cb' and 'id' columns to find the first data column.
202+
$skip_columns = array( 'cb', 'id' );
203+
204+
foreach ( $columns as $key => $label ) {
205+
if ( in_array( $key, $skip_columns, true ) ) {
206+
continue;
207+
}
208+
209+
// The first column we encounter after skipping is the first data column.
210+
return $key === $column_name;
211+
}
212+
213+
return false;
214+
}
215+
181216
/**
182217
* Column with a checkbox
183218
* Used for bulk actions

0 commit comments

Comments
 (0)