Created
November 1, 2018 10:28
-
-
Save andrewlimaza/2d7a2b446bcd475b773729acc2cc9e19 to your computer and use it in GitHub Desktop.
Paid Memberships Pro Renew Membership Shortcode
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 this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* Add the [pmpro_renew_button] shortcode to any page or post. | |
*/ | |
// lets build a shortcode | |
function my_pmpro_renew_membership_shortcode() { | |
global $current_user, $pmpro_pages; | |
// Current user empty (i.e. not logged in) | |
if ( empty( $current_user ) ) { | |
return; | |
} | |
$level = pmpro_getMembershipLevelForUser( $current_user->ID ); | |
// If the user does not have a membership level, don't display anything. | |
if( empty( $level ) ) { | |
return; | |
} | |
$level_id = $level->id; | |
$url = add_query_arg( 'level', $level_id, get_permalink( $pmpro_pages['checkout'] ) ); | |
return '<a href="' . $url . '">Renew Membership</a>'; | |
} | |
add_shortcode( 'pmpro_renew_button', 'my_pmpro_renew_membership_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment