Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save strangerstudios/5382962 to your computer and use it in GitHub Desktop.
Save strangerstudios/5382962 to your computer and use it in GitHub Desktop.
Add a custom field to the members list CSV export in Paid Memberships Pro.
<?php
/*
Add employer, title, and department columns to the members list CSV export.
Just add this code to your functions.php or a custom plugin.
The first function here defines the column headers and a callback function for each column.
*/
function my_pmpro_members_list_csv_extra_columns($columns)
{
$columns["employer"] = "my_extra_column_employer";
$columns["title"] = "my_extra_column_title";
$columns["department"] = "my_extra_column_department";
return $columns;
}
add_filter("pmpro_members_list_csv_extra_columns", "my_pmpro_members_list_csv_extra_columns", 10);
/*
These are the callback functions which take the $user object from the CSV code (which includes an array of meta data in ->metavalues, and returns the value you want.
I expanded the code for this first function for readability, but if you have a bunch of these, you may want to scrunch them up onto one line each.
*/
function my_extra_column_employer($user)
{
if(!empty($user->metavalues->employer))
{
return $user->metavalues->employer;
}
else
{
return "";
}
}
function my_extra_column_title($user){if(!empty($user->metavalues->title)){return $user->metavalues->title;}else{return "";}}
function my_extra_column_department($user){if(!empty($user->metavalues->department)){return $user->metavalues->department;}else{return "";}}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment