Created
July 31, 2018 10:20
-
-
Save andrewlimaza/354abf55f23f9cc1b1d0b3e6be7acc91 to your computer and use it in GitHub Desktop.
Get user's startdate for Paid Memberships Pro
This file contains hidden or 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 | |
| /** | |
| * 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