Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidmutero/f7acc22ebe7d93eb6516a92cd9c10681 to your computer and use it in GitHub Desktop.
Save davidmutero/f7acc22ebe7d93eb6516a92cd9c10681 to your computer and use it in GitHub Desktop.
Add Level Group Columns in Members List CSV Export
<?php
/**
* Adds "Group One" and "Group Two" columns to the PMPro Members List CSV export.
* Each column includes level names based on static arrays of level IDs.
*
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_members_list_static_columns( $columns ) {
$columns['group_one'] = 'my_pmpro_get_group_one_column'; // Column title will be "Group One"
$columns['group_two'] = 'my_pmpro_get_group_two_column'; // Column title will be "Group Two"
return $columns;
}
add_filter( 'pmpro_members_list_csv_extra_columns', 'my_pmpro_members_list_static_columns' );
function my_pmpro_get_group_one_column( $user ) {
$group_one_ids = array( 1, 2, 3 ); // Set level IDs for Group One
$levels = pmpro_getMembershipLevelsForUser( $user->ID );
$matches = array();
foreach ( $levels as $level ) {
if ( in_array( $level->id, $group_one_ids ) ) $matches[] = $level->name;
}
return implode( ', ', $matches );
}
function my_pmpro_get_group_two_column( $user ) {
$group_two_ids = array( 4, 5 ); // Set level IDs for Group Two
$levels = pmpro_getMembershipLevelsForUser( $user->ID );
$matches = array();
foreach ( $levels as $level ) {
if ( in_array( $level->id, $group_two_ids ) ) $matches[] = $level->name;
}
return implode( ', ', $matches );
}
add_filter( 'pmpro_members_list_csv_extra_columns_data', 'my_pmpro_get_group_one_column', 10, 2 );
add_filter( 'pmpro_members_list_csv_extra_columns_data', 'my_pmpro_get_group_two_column', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment