Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pbrocks/490bb0d77b412947007fb1187d6bc716 to your computer and use it in GitHub Desktop.
Save pbrocks/490bb0d77b412947007fb1187d6bc716 to your computer and use it in GitHub Desktop.
Show start date of current membership on the PMPro members list.
<?php
/**
* Show start date of current membership on the members list
* and members list CSV export.
*
* By default, PMPro will show the "Join Date" on the members list,
* which is the date the WP user was created. If you need to know
* the date the user upgraded to their current level, you can
* add this code to your active theme's functions.php or a custom plugin.
*/
// header
function my_pmpro_memberslist_extra_cols_header_startdate() {
?>
<th>Started This Level</th>
<?php
}
add_action( 'pmpro_memberslist_extra_cols_header', 'my_pmpro_memberslist_extra_cols_header_startdate' );
// column
function my_pmpro_memberslist_extra_cols_body_startdate( $user ) {
echo '<td>';
$level = pmpro_getMembershipLevelForUser( $user->ID );
if ( ! empty( $level ) && ! empty( $level->startdate ) ) {
echo date( get_option( 'date_format', $level->startdate ) );
} else {
echo 'N/A';
}
echo '</td>';
}
add_action( 'pmpro_memberslist_extra_cols_body', 'my_pmpro_memberslist_extra_cols_body_startdate' );
// export header
function my_pmpro_members_list_csv_extra_columns_startdate( $columns ) {
$columns['membership_startdate'] = 'my_extra_column_membership_startdate';
return $columns;
}
add_filter( 'pmpro_members_list_csv_extra_columns', 'my_pmpro_members_list_csv_extra_columns_startdate', 10 );
// export column
function my_extra_column_membership_startdate( $user ) {
if ( empty( $user->membership_id ) ) {
return '';
}
global $wpdb;
$startdate = $wpdb->get_var( "SELECT UNIX_TIMESTAMP(startdate) as startdate FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND membership_id = '" . $user->membership_id . "' ORDER BY id DESC LIMIT 1" );
if ( ! empty( $startdate ) ) {
return date( 'Y-m-d', $startdate );
} else {
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment