Skip to content
Merged
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
41 changes: 38 additions & 3 deletions src/class-acm-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,50 @@ function column_default( $item, $column_name ) {
case 'operator':
return ( ! empty( $item['operator'] ) ) ? $item['operator'] : $ad_code_manager->logical_operator;
default:
// @todo need to make the first column (whatever it is filtered) to show row actions
// Handle custom columns, if any
// Handle custom columns, if any.
if ( isset( $item['url_vars'][ $column_name ] ) ) {
return esc_html( $item['url_vars'][ $column_name ] );
$output = esc_html( $item['url_vars'][ $column_name ] );

// Add row actions to the first data column (after cb and id).
if ( $this->is_first_data_column( $column_name ) ) {
$output .= $this->row_actions_output( $item );
}

return $output;
}
break;
}
}

/**
* Check if the given column is the first data column.
*
* The first data column is the first column after 'cb' (checkbox) and 'id' (hidden).
* This column should display the row actions (edit/delete links).
*
* @since 0.8.0
*
* @param string $column_name The column name to check.
* @return bool True if this is the first data column, false otherwise.
*/
protected function is_first_data_column( $column_name ) {
$columns = $this->get_columns();

// Skip 'cb' and 'id' columns to find the first data column.
$skip_columns = array( 'cb', 'id' );

foreach ( $columns as $key => $label ) {
if ( in_array( $key, $skip_columns, true ) ) {
continue;
}

// The first column we encounter after skipping is the first data column.
return $key === $column_name;
}

return false;
}

/**
* Column with a checkbox
* Used for bulk actions
Expand Down