scott
(Scott Gingrich)
April 1, 2021, 2:05pm
1
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
bogdan
(Bogdan Rapaić)
April 1, 2021, 5:39pm
2
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
scott
(Scott Gingrich)
April 1, 2021, 8:30pm
3
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
bogdan
(Bogdan Rapaić)
April 2, 2021, 3:23pm
4
Hi Scott,
I am happy to see it worked like expected.
system
(system)
Closed
April 3, 2021, 3:24pm
5
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.