Last active
November 11, 2024 16:02
-
-
Save strangerstudios/3a5c0c6fecdd8c52ff328bc28aa3ec18 to your computer and use it in GitHub Desktop.
Add columns to the Members List CSV Export.
This file contains 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 | |
/* | |
Add data from the wp_users, wp_user_meta, or BuddyPress xProfile fields tables to the Members List CSV Export. | |
The pmpro_members_list_csv_extra_columns passes an array of columns. | |
The keys of the array are the column headings. The values are callback functions to get the value for that row. | |
*/ | |
//add the column to the export | |
function my_pmpro_members_list_csv_extra_columns ( $columns ) { | |
$columns["column_a"] = "my_pmpro_members_list_column_a"; | |
$columns["column_b"] = "my_pmpro_members_list_column_b"; | |
$columns["field_1_bp"] = "my_pmpro_members_list_field_1_bp"; | |
return $columns; | |
} | |
add_filter( 'pmpro_members_list_csv_extra_columns', 'my_pmpro_members_list_csv_extra_columns', 10 ); | |
//call back to get the column a value | |
function my_pmpro_members_list_column_a ( $user ) { | |
//this is an example to retrive user meta | |
$column_a_value = get_user_meta( $user->ID, 'description', true ); | |
return $column_a_value; | |
} | |
//call back to get the column b value | |
function my_pmpro_members_list_column_b ( $user ) { | |
//this is an example to retrive userdata | |
$column_b_value = $user->user_url; | |
return $column_b_value; | |
} | |
//call back to get the BuddyPress field ID 1 value | |
function my_pmpro_members_list_field_1_bp ( $user ) { | |
$field_1_bp_value = bp_get_profile_field_data( array( 'field' => '1', 'user_id' => $user->ID ) ); | |
return $field_1_bp_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Exporting Your Members List: Default Data and Adding New Columns" at Paid Memberships Pro here: https://www.paidmembershipspro.com/exporting-members-list-default-data-adding-new-columns/