Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created July 31, 2018 10:20
Show Gist options
  • Save andrewlimaza/354abf55f23f9cc1b1d0b3e6be7acc91 to your computer and use it in GitHub Desktop.
Save andrewlimaza/354abf55f23f9cc1b1d0b3e6be7acc91 to your computer and use it in GitHub Desktop.
Get user's startdate for Paid Memberships Pro
<?php
/**
* Creates a shortcode [member_startdate] and returns a readable date if the user has a membership startdate.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_shortcode_example() {
global $wpdb, $current_user;
$user_id = $current_user->ID;
if ( ! empty( $user_id ) ) {
$startdate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(startdate) as startdate FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user_id . "'");
}
if ( ! empty( $startdate ) ) {
return date( 'Y-m-d', $startdate ); // Just return $startdate; if you want unix_timestamp only.
} else {
return 'No date';
}
}
add_shortcode( 'member_startdate', 'my_shortcode_example' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment