Create Custom Column in the Manage Sites table with Data from Client data

Creating a custom column with Client data should be fairly simple, here is a code example for creating a Client Email column that will show your client’s email address saved in the Side Edit page for the [client.email] token.

You can simply save the snippet to the PHP section of the Custom Dashboard extension, and that is it.

If you are using the Client Reports extension:

add_filter( 'mainwp_sitestable_getcolumns', 'mycustom_mainwp_sitestable_getcolumns', 10, 1 );
function mycustom_mainwp_sitestable_getcolumns( $columns ) {
	$columns['client_email'] = "Client Email";
	return $columns;
}

add_filter( 'mainwp_sitestable_item', 'mycustom_mainwp_sitestable_item', 10, 1 );
function mycustom_mainwp_sitestable_item( $item ) {
	$tokens = apply_filters(  'mainwp_client_report_get_site_tokens', false,  $item['id'] );
	if ( is_array( $tokens ) && isset( $tokens['[client.email]'] ) ) {
	    $item['client_email'] = $tokens['[client.email]'];
	}
	return $item;
}

If you are using the Pro Reports extension:

add_filter( 'mainwp_sitestable_getcolumns', 'mycustom_mainwp_sitestable_getcolumns', 10, 1 );
function mycustom_mainwp_sitestable_getcolumns( $columns ) {
	$columns['client_email'] = "Client Email";
	return $columns;
}

add_filter( 'mainwp_sitestable_item', 'mycustom_mainwp_sitestable_item', 10, 1 );
function mycustom_mainwp_sitestable_item( $item ) {
	$tokens = apply_filters(  'mainwp_pro_reports_get_site_tokens', false,  $item['id'] );
	if ( is_array( $tokens ) && isset( $tokens['[client.email]'] ) ) {
	    $item['client_email'] = $tokens['[client.email]'];
	}
	return $item;
}
2 Likes

This is great. Is it possible to change the order of the columns?

1 Like

Hi Scott,

yes, columns in MainWP tables can easily be reordered if you drag and drop them to wanted place.

Thanks!

OK, mind blown. I feel like such a newb. Thanks for the quick reply (and not making fun of me for not knowing already! LOL) I manage well over 100 sites on MainWP and continue to “move into” all that it offers.

2 Likes

Hi Scott,

thanks for getting back to me.

I am glad I could help.