Filter (wpda_column_default) to influence column layout in list table

A filter named wpda_column_default was added to influence the layout of list table columns. The filter is not called on the first column to prevent links not being displayed correctly.

Example

function my_column_default(
	$value,
	$item,
	$column_name,
	$table_name,
	$schema_name,
	$wpda_list_columns,
	$list_number,
	$this
) {
	if ( '' !== $value ) {
		return $value;
	}

	if ( 'dutch' === $column_name ) {
		return 'NL-' . $item[ $column_name ];
	}
}
add_filter( 'wpda_column_default' , 'my_column_default' , 10 , 8 );

Note

You can use this filter in combination with action hook wpda_after_list_table to add interactive elements to your list tables.

Function declaration

wpda_column_default( $item, $column_name, $table_name, $schema_name, $wpda_list_columns, $list_number )

$value

Current column value

$item

Associative array containing the column name of all columns in the list table and their value

$column_name

Column name

$table_name

Database table name

$schema_name

Database (schema) name

$wpda_list_columns

Reference to column list (instance of class WPDA_List_Columns)

$list_number

Row number in the current list

$self

Calling WPDA_List_table object

Peter Schulz is a lecturer in information technology at the HAN university of applied sciences. He is an experienced programmer with more than 25 years experience in Oracle databases and tools. Peter is the developer of WordPress plugin WP Data Access.

5 Replies to “Filter (wpda_column_default) to influence column layout in list table”

  1. Hi,

    added the following to my theme functions.php:

    function my_offers_custom_function ($item, $column_name) {
    if (‘reference’ === $column_name) {
    return $item[ $column_name ] . ‘.’;
    }
    }
    add_filter(‘wpda_column_default’, ‘my_offers_custom_function’, 10, 2);

    function my_offers_custom_elements() {
    return “console.log(‘teste’);”;
    }
    add_action( ‘wpda_extend_list_table’, ‘my_offers_custom_elements’);

    But it doesn’t add the ‘.’ to the end of the values in column reference.
    And in the dev tools, doesn’t show the console.log…

    Can you provide some guidance, please? TY

  2. Hi Miguel,

    The description of filter wpda_column_default was outdated. The filter takes 6 arguments. I updated the example and the function declaration. Hope this helps! Sorry…

    Action hook wpda_extend_list_table is just meant to add content, scripts or styles below your list table. I guess it works when you put the console.log in a script tag. Like this:

    function my_offers_custom_elements() {
    return ““;
    }
    add_action( ‘wpda_extend_list_table’, ‘my_offers_custom_elements’ );

    Best regards,
    Peter

  3. Looks like my script tag was deleted… 🙂 New attempt:

    function my_offers_custom_elements() {
    return “< s c r i p t >console.log(‘teste’);< / s c r i p t >”;
    }

    Don’t forget to remove the spaces and change the quotes and the double quotes…

Leave a Reply

Your email address will not be published. Required fields are marked *