How to add custom contact table columns

Full code example:

<?php

// pre 2.0
add_action( 'wpgh_contact_columns', 'add_my_custom_column' );

// 2.0
add_action( 'groundhogg_contact_columns', 'add_my_custom_column' );

function add_my_custom_column( $cols ){

    $cols[ 'my_col' ] = __( 'My Column' );

    return $cols;

}

// pre 2.0
add_action( 'wpgh_contacts_custom_column', 'show_my_custom_column', 10, 2 );

// 2.0
add_action( 'groundhogg_contacts_custom_column', 'show_my_custom_column', 10, 2 );

/**
 * @param $contact \Groundhogg\Contact
 * @param $column_name string
 */
function show_my_custom_column( $contact, $column_name )
{
    if ( $column_name === 'my_col' ){
        print_r( '<a href="%s">%s</a>', add_query_arg( [ 'page' => 'gh_contacts','meta_key' => 'lead_attribution','meta_value' => urlencode( $contact->get_meta( 'lead_attribution' )) ], admin_url( 'admin.php' ) ), esc_html( $contact->get_meta( 'lead_attribution' ) ) );
    }
}

?>
Was this article helpful to you? Yes No

How can we help?