[Solved] Add second field to dashboard

I currently have a PHP snippet for the custom dashboard extension to show the email field. I’d like to add contact name as well but I’m not sure how to modify the code to add a second field. Any PHP wizards out there who can assist?

The field I’m wanting to add is [client.name].

Here’s the code I’m using currently:

//Add Client email to sites screen
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;
}

Thanks in advance!

Scott

Hi Scott,

It should be fairly simple to add another column by adding another element to exisitng array.

//Add Client email to sites screen
add_filter( 'mainwp_sitestable_getcolumns', 'mycustom_mainwp_sitestable_getcolumns', 10, 1 );
function mycustom_mainwp_sitestable_getcolumns( $columns ) {
	$columns['client_email'] = "Client Email";
	$columns['client_name'] = "Client Name";	
	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]'];
	}
    if ( is_array( $tokens ) && isset( $tokens['[client.name]'] ) ) {
	    $item['client_name'] = $tokens['[client.name]'];
	}
	return $item;
}
2 Likes

Well, when you put it that way, it’s easy!! LOL

THANK YOU for the quick response. Worked like a charm.

With much apprceation,

Scott

2 Likes

Hi Scott,

I am happy to see it worked like expected.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.