Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created December 12, 2019 12:00
Show Gist options
  • Save andrewlimaza/9ad3646998561ea0fac501905b5c149a to your computer and use it in GitHub Desktop.
Save andrewlimaza/9ad3646998561ea0fac501905b5c149a to your computer and use it in GitHub Desktop.
Shortcode to show a list of last five members registered - Paid Memberships Pro
<?php
/**
* Show a list of users that recently signed up. Currently only shows user names and the last 5 registrations.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Use [pmpro_latest_members] shortcode to display a list of users.
*/
function pmpro_show_latest_members_name_shortcode() {
global $wpdb;
if ( empty( get_transient( 'pmpro_latest_members' ) ) ) {
$sql = "SELECT u.user_nicename FROM $wpdb->pmpro_memberships_users m LEFT JOIN $wpdb->users u ON u.ID = m.user_id WHERE m.status = 'active' ORDER BY m.startdate DESC LIMIT 5";
$results = $wpdb->get_results( $sql );
if ( ! empty( $results ) && is_array( $results ) ) {
// Set the transient in here for now.
set_transient( 'pmpro_latest_members', $results, 12 * HOUR_IN_SECONDS );
}
} else {
$results = get_transient( 'pmpro_latest_members' );
}
// Output the results now.
if ( ! empty( $results ) && is_array( $results ) ) {
$output = "<ul>";
foreach( $results as $name ) {
$output .= "<li>" . $name->user_nicename . "</li>";
}
$output .= "</ul>";
return $output;
} else {
return 'No members found.';
}
}
add_shortcode( 'pmpro_latest_members', 'pmpro_show_latest_members_name_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment