Created
April 9, 2025 11:22
-
-
Save davidmutero/f7acc22ebe7d93eb6516a92cd9c10681 to your computer and use it in GitHub Desktop.
Add Level Group Columns in Members List CSV Export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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