Forked from strangerstudios/my_pmpro_members_list_csv_extra_columns.php
Created
November 11, 2024 16:02
-
-
Save kimwhite/eda0f01c26bd98febd92972968ceb13e 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 pmpro_memberships_users table | |
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["startdate"] = "my_pmpro_members_list_column_a"; | |
return $columns; | |
} | |
add_filter( 'pmpro_members_list_csv_extra_columns', 'my_pmpro_members_list_csv_extra_columns', 10 ); | |
// Callback to get the start date column value | |
function my_pmpro_members_list_column_a( $user ) { | |
global $wpdb; | |
// Query the 'startdate' for the specific user | |
$startdate = $wpdb->get_var( | |
$wpdb->prepare( | |
"SELECT startdate | |
FROM {$wpdb->prefix}pmpro_memberships_users | |
WHERE user_id = %d | |
ORDER BY id DESC | |
LIMIT 1", | |
$user->ID | |
) | |
); | |
// Format the date if it exists, otherwise return empty | |
return $startdate ? date('Y-m-d', strtotime($startdate)) : ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment