Paid Memberships Pro Shortcodes

Below, you’ll find a detailed guide on how to add the Paid Memberships Pro Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Paid Memberships Pro Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Paid Memberships Pro Plugin and the shortcodes it provides:

Plugin Icon
Paid Memberships Pro – Content Restriction, User Registration, & Paid Subscriptions

"Paid Memberships Pro is a versatile plugin allowing content restriction, user registration, and paid subscriptions. It's your ideal solution for monetizing a WordPress site effectively."

★★★★✩ (592) Active Installs: 90000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [pmpro_pages_shortcode]
  • [pmpro_checkout_button]
  • [membership]
  • [pmpro_account]
  • [pmpro_login]
  • [pmpro_member]
  • [pmpro_member_profile_edit]

Paid Memberships Pro [pmpro_pages_shortcode] Shortcode

The Paid Memberships Pro shortcode is a tool to load specific page templates. It uses the global variable $pmpro_page_name to identify the template to load. This shortcode function retrieves the template associated with the page name and applies any filters specific to that page. It ultimately returns the content of the specified template.

Shortcode: [pmpro_pages_shortcode]

Examples and Usage

Basic example – The basic usage of the shortcode to display the membership level page.

[pmpro_membership]

PHP Function Code

In case you have difficulties debugging what causing issues with [pmpro_pages_shortcode] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode("pmpro_" . $pmpro_page_name, "pmpro_pages_shortcode");

Shortcode PHP function:

function pmpro_pages_shortcode($atts, $content=null, $code="")
				{
					global $pmpro_page_name;
					$temp_content = pmpro_loadTemplate($pmpro_page_name, 'local', 'pages');
					return apply_filters("pmpro_pages_shortcode_" . $pmpro_page_name, $temp_content);
				}

Code file location:

paid-memberships-pro/paid-memberships-pro/includes/init.php

Paid Memberships Pro [pmpro_checkout_button] Shortcode

The Paid Memberships Pro shortcode is a handy tool for adding a checkout button on your site. It allows you to specify the membership level, button text, and CSS class. This shortcode uses PHP to extract attributes and output a span element with a specific class. The pmpro_getCheckoutButton function is then called to generate the button.

Shortcode: [pmpro_checkout_button]

Parameters

Here is a list of all possible pmpro_checkout_button shortcode parameters and attributes:

  • level – Specifies the membership level for the checkout button
  • text – Defines the text displayed on the checkout button
  • class – Assigns a CSS class to the checkout button for styling

Examples and Usage

Basic example – Showcases a simple usage of the pmpro_checkout_button shortcode, which generates a checkout button for a specified membership level.

[pmpro_checkout_button level="1"]

Advanced examples

Creating a checkout button for a specific membership level with custom text. This shortcode will generate a checkout button for membership level 2, and the button text will be “Sign up now”.

[pmpro_checkout_button level="2" text="Sign up now"]

Creating a checkout button with a specific membership level, custom text, and custom class. This shortcode will generate a checkout button for membership level 3, the button text will be “Join us”, and the button will have the class “my-custom-class”. The class can be styled using CSS for a unique appearance.

[pmpro_checkout_button level="3" text="Join us" class="my-custom-class"]

PHP Function Code

In case you have difficulties debugging what causing issues with [pmpro_checkout_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode("pmpro_button", "pmpro_checkout_button_shortcode");

Shortcode PHP function:

function pmpro_checkout_button_shortcode($atts, $content=null, $code="")
{
	// $atts    ::= array of attributes
	// $content ::= text within enclosing form of shortcode element
	// $code    ::= the shortcode found, when == callback name
	// examples: [pmpro_checkout_button level="3"]

	extract(shortcode_atts(array(
		'level' => NULL,
		'text' => NULL,
		'class' => NULL
	), $atts));
	
	ob_start(); ?>
 	<span class="<?php esc_attr( pmpro_get_element_class( 'span_pmpro_checkout_button' ) ); ?>">
 		<?php
			//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			echo pmpro_getCheckoutButton($level, $text, $class);
		?>
 	</span>
 	<?php
 	return ob_get_clean();
}

Code file location:

paid-memberships-pro/paid-memberships-pro/shortcodes/checkout_button.php

Paid Memberships Pro [membership] Shortcode

The Paid Memberships Pro shortcode “membership” is used to control content visibility based on user membership level. This shortcode checks if the user has a specific membership level or any level if not specified. It also allows setting a delay, restricting access until a certain period of membership is reached. If the user doesn’t meet these criteria, a no-access message is displayed.

Shortcode: [membership]

Parameters

Here is a list of all possible membership shortcode parameters and attributes:

  • level – Specifies a particular membership level to check
  • levels – Alternative to ‘level’, can specify multiple membership levels
  • delay – Sets a delay in days before content is accessible
  • show_noaccess – Determines if a ‘no access’ message is shown when access is denied

Examples and Usage

Basic example – The following example demonstrates the basic usage of the membership shortcode. It checks if the user has a membership of level 3 and displays the enclosed content if they do.

[membership level="3"]Your exclusive content here[/membership]

Advanced examples

Displaying content based on multiple membership levels. This shortcode checks if the user has a membership of level 3 or 5. If they do, the enclosed content will be displayed.

[membership level="3,5"]Your exclusive content here[/membership]

Displaying content based on membership level and after a certain delay. This shortcode checks if the user has a membership of level 3 and if they have been a member for at least 7 days. If both conditions are met, the enclosed content will be displayed.

[membership level="3" delay="7"]Your exclusive content here[/membership]

Displaying a no access message for non-members. This shortcode checks if the user has a membership of level 3. If they do not, a no access message will be displayed.

[membership level="3" show_noaccess="true"]Your exclusive content here[/membership]

PHP Function Code

In case you have difficulties debugging what causing issues with [membership] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode("membership", "pmpro_shortcode_membership");

Shortcode PHP function:

function pmpro_shortcode_membership($atts, $content=null, $code="")
{
	// $atts    ::= array of attributes
	// $content ::= text within enclosing form of shortcode element
	// $code    ::= the shortcode found, when == callback name
	// examples: [membership level="3"]...[/membership]

	extract(shortcode_atts(array(
		'level' => NULL,
		'levels' => NULL,
		'delay' => NULL,
		'show_noaccess' => NULL
	), $atts));

	//if levels is used instead of level
	if(isset($levels) && !isset($level))
		$level = $levels;
	
	global $wpdb, $current_user;

	//guilty until proven innocent :)
	$hasaccess = false;

	//figure out which level/levels to check
	if(!empty($level) || $level === "0" || $level === 0)
	{
	   //they specified a level(s)
	   if(strpos($level, ","))
	   {
		   //they specified many levels
		   $levels = explode(",", $level);
	   }
	   else
	   {
		   //they specified just one level
		   $levels = array($level);
	   }	   
	}
	else
	{
		//didn't specify a membership level, so use false so pmpro_hasMembershipLevel checks for any level
		$levels = false;
	}

	//check their level
	if(pmpro_hasMembershipLevel($levels))
		   $hasaccess = true;

	//is there a delay?
	if($hasaccess && !empty($delay))
	{		
		//okay, this post requires membership. start by getting the user's startdate
		if(!empty($levels))
			$sqlQuery = "SELECT UNIX_TIMESTAMP(CONVERT_TZ(startdate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND membership_id IN(" . implode(",", array_map( 'intval', $levels ) ) . ") AND user_id = '" . esc_sql( $current_user->ID ) . "' ORDER BY id LIMIT 1";
		else
			$sqlQuery = "SELECT UNIX_TIMESTAMP(CONVERT_TZ(startdate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND user_id = '" . esc_sql( $current_user->ID ) . "' ORDER BY id LIMIT 1";

		$startdate = $wpdb->get_var($sqlQuery);

		//adjust start date to 12AM
		$startdate = strtotime(date_i18n("Y-m-d", $startdate));

		if(empty($startdate))
		{
			//user doesn't have an active membership level
			$hasaccess = false;
		}
		else
		{
			//how many days has this user been a member?
			$now = current_time('timestamp');
			$days = ($now - $startdate)/3600/24;

			if($days < intval($delay))
				$hasaccess = false;	//they haven't been around long enough yet
		}
	}

	// Filter the $hasaccess so we can overwrite this for other add ons.
	$hasaccess = apply_filters( 'pmpro_member_shortcode_access', $hasaccess, $content, $levels, $delay );

	//to show or not to show
	if($hasaccess)
		return do_shortcode($content);	//show content
	else {
		if ( empty( $show_noaccess ) ) {
			return '';
		} else {
			$content = '';
			return pmpro_get_no_access_message( $content, $levels );
		}
	}
}

Code file location:

paid-memberships-pro/paid-memberships-pro/shortcodes/membership.php

Paid Memberships Pro [pmpro_account] Shortcode

The Paid Memberships Pro shortcode allows users to customize their account page on a WordPress site. It provides options to display various sections such as membership details, profile information, past invoices, and member links. By using this shortcode, users can easily manage their subscriptions, update profile and billing details, view past invoices, and access specific member links, all in one place. It’s a powerful tool for enhancing user experience on membership-based sites.

Shortcode: [pmpro_account]

Parameters

Here is a list of all possible pmpro_account shortcode parameters and attributes:

  • section – specifies a single section to display in the account page
  • sections – defines multiple sections to display such as membership, profile, invoices, and links
  • title – sets a custom title for a single section being displayed

Examples and Usage

Basic example – Displaying a user’s account information with default sections (Membership, Profile, Invoices, Links).

[pmpro_account]

Advanced examples

Displaying a user’s account information with only ‘membership’ and ‘profile’ sections.

[pmpro_account sections="membership,profile"]

Displaying a user’s account information with a custom title for the section.

[pmpro_account title="My Custom Title"]

Displaying a user’s account information with only ‘invoices’ section and a custom title.

[pmpro_account sections="invoices" title="My Billing History"]

PHP Function Code

In case you have difficulties debugging what causing issues with [pmpro_account] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('pmpro_account', 'pmpro_shortcode_account');

Shortcode PHP function:

function pmpro_shortcode_account($atts, $content=null, $code="")
{
	global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;

	// $atts    ::= array of attributes
	// $content ::= text within enclosing form of shortcode element
	// $code    ::= the shortcode found, when == callback name
	// examples: [pmpro_account] [pmpro_account sections="membership,profile"/]

	extract(shortcode_atts(array(
		'section' => '',
		'sections' => 'membership,profile,invoices,links',
		'title' => null,
	), $atts));

	//did they use 'section' instead of 'sections'?
	if(!empty($section))
		$sections = $section;

	//Extract the user-defined sections for the shortcode
	$sections = array_map('trim',explode(",",$sections));
	ob_start();

	// If multiple sections are being shown, set title to null.
	// Titles can only be changed from the default if only one section is being shown.
	if ( count( $sections ) > 1 ) {
		$title = null;
	}

	//if a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
	$order = new MemberOrder();
	$order->getLastMemberOrder();
	$mylevels = pmpro_getMembershipLevelsForUser();
	$pmpro_levels = pmpro_getAllLevels(false, true); // just to be sure - include only the ones that allow signups
	$invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(CONVERT_TZ(timestamp, '+00:00', @@global.time_zone)) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND status NOT IN('review', 'token', 'error') ORDER BY timestamp DESC LIMIT 6");
	?>
	<div id="pmpro_account">
		<?php if(in_array('membership', $sections) || in_array('memberships', $sections)) { ?>
			<div id="pmpro_account-membership" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_box', 'pmpro_account-membership' ) ); ?>">
				<?php
				if ( '' !== $title ) { // Check if title is being forced to not show.
					// If a custom title was not set, use the default. Otherwise, show the custom title.
					?>
					<h2><?php echo esc_html( null === $title ? __( 'My Memberships', 'paid-memberships-pro' ) : $title ); ?></h2>
					<?php
				}
				?>
				<table class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table' ) ); ?>" width="100%" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<tr>
							<th><?php esc_html_e("Level", 'paid-memberships-pro' );?></th>
							<th><?php esc_html_e("Billing", 'paid-memberships-pro' ); ?></th>
							<th><?php esc_html_e("Expiration", 'paid-memberships-pro' ); ?></th>
						</tr>
					</thead>
					<tbody>
						<?php if ( empty( $mylevels ) ) { ?>
						<tr>
							<td colspan="3">
							<?php
							// Check to see if the user has a cancelled order
							$order = new MemberOrder();
							$order->getLastMemberOrder( $current_user->ID, array( 'cancelled', 'expired', 'admin_cancelled' ) );

							if ( isset( $order->membership_id ) && ! empty( $order->membership_id ) && empty( $level->id ) ) {
								$level = pmpro_getLevel( $order->membership_id );
							}

							// If no level check for a default level.
							if ( empty( $level ) || ! $level->allow_signups ) {
								$default_level_id = apply_filters( 'pmpro_default_level', 0 );
							}

							// Show the correct checkout link.
							if ( ! empty( $level ) && ! empty( $level->allow_signups ) ) {
								$url = pmpro_url( 'checkout', '?level=' . $level->id );
								echo wp_kses( sprintf( __( "Your membership is not active. <a href='%s'>Renew now.</a>", 'paid-memberships-pro' ), $url ), array( 'a' => array( 'href' => array() ) ) );
							} elseif ( ! empty( $default_level_id ) ) {
								$url = pmpro_url( 'checkout', '?level=' . $default_level_id );
								echo wp_kses( sprintf( __( "You do not have an active membership. <a href='%s'>Register here.</a>", 'paid-memberships-pro' ), $url ), array( 'a' => array( 'href' => array() ) ) );
							} else {
								$url = pmpro_url( 'levels' );
								echo wp_kses( sprintf( __( "You do not have an active membership. <a href='%s'>Choose a membership level.</a>", 'paid-memberships-pro' ), $url ), array( 'a' => array( 'href' => array() ) ) );
							}
							?>
							</td>
						</tr>
							<?php } else { ?>
							<?php
								foreach($mylevels as $level) {
							?>
							<tr>
								<td class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_account-membership-levelname' ) ); ?>">
									<?php echo esc_html( $level->name ); ?>
									<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_actionlinks' ) ); ?>">
										<?php do_action("pmpro_member_action_links_before"); ?>

										<?php
										// Build the links to return.
										$pmpro_member_action_links = array();

										if( array_key_exists($level->id, $pmpro_levels) && pmpro_isLevelExpiringSoon( $level ) ) {
											$pmpro_member_action_links['renew'] = '<a id="pmpro_actionlink-renew" href="' . esc_url( add_query_arg( 'level', $level->id, pmpro_url( 'checkout', '', 'https' ) ) ) . '" aria-label="' . esc_html__( sprintf( esc_html__( 'Renew %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Renew', 'paid-memberships-pro' ) . '</a>';
										}

										if((isset($order->status) && $order->status == "success") && (isset($order->gateway) && in_array($order->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource"))) && pmpro_isLevelRecurring($level)) {
											$pmpro_member_action_links['update-billing'] = '<a id="pmpro_actionlink-update-billing" href="' . esc_url( pmpro_url( 'billing', '', 'https' ) ) . '" aria-label="' . esc_html__( sprintf( esc_html__( 'Update Billing Info for %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Update Billing Info', 'paid-memberships-pro' ) . '</a>';
										}

										//To do: Only show CHANGE link if this level is in a group that has upgrade/downgrade rules
										if(count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
											$pmpro_member_action_links['change'] = '<a id="pmpro_actionlink-change" href="' . esc_url( pmpro_url( 'levels' ) ) . '" aria-label="' . esc_html__( sprintf( esc_html__( 'Change %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Change', 'paid-memberships-pro' ) . '</a>';
										}

										$pmpro_member_action_links['cancel'] = '<a id="pmpro_actionlink-cancel" href="' . esc_url( add_query_arg( 'levelstocancel', $level->id, pmpro_url( 'cancel' ) ) ) . '" aria-label="' . esc_html__( sprintf( esc_html__( 'Cancel %1$s Membership', 'paid-memberships-pro' ), $level->name ) ) . '">' . esc_html__( 'Cancel', 'paid-memberships-pro' ) . '</a>';

										/**
										 * Filter the member action links.
										 *
										 * @param array $pmpro_member_action_links Member action links.
										 * @param int   $level->id The ID of the membership level.
										 * @return array $pmpro_member_action_links Member action links.
										 */
										$pmpro_member_action_links = apply_filters( 'pmpro_member_action_links', $pmpro_member_action_links, $level->id );

										$allowed_html = array(
											'a' => array (
												'class' => array(),
												'href' => array(),
												'id' => array(),
												'target' => array(),
												'title' => array(),
												'aria-label' => array(),
											),
										);
										echo wp_kses( implode( pmpro_actions_nav_separator(), $pmpro_member_action_links ), $allowed_html );
										?>

										<?php do_action("pmpro_member_action_links_after"); ?>
									</div> <!-- end pmpro_actionlinks -->
								</td>
								<td class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_account-membership-levelfee' ) ); ?>">
									<p><?php echo wp_kses_post( pmpro_getLevelCost($level, true, true) );?></p>
								</td>
								<td class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_account-membership-expiration' ) ); ?>">
									<?php
										$expiration_text = '<p>';
										if ( $level->enddate ) {
											$expiration_text .= date_i18n( get_option( 'date_format' ), $level->enddate );
											/**
											 * Filter to include the expiration time with expiration date
											 *
											 * @param bool $pmpro_show_time_on_expiration_date Show the expiration time with expiration date (default: false).
											 *
											 * @return bool $pmpro_show_time_on_expiration_date Whether to show the expiration time with expiration date.
											 *
											 */
											if ( apply_filters( 'pmpro_show_time_on_expiration_date', false ) ) {
												$expiration_text .= ' ' . date_i18n( get_option( 'time_format', __( 'g:i a' ) ), $level->enddate );
											}
										} else {
											$expiration_text .= esc_html_x( '&#8212;', 'A dash is shown when there is no expiration date.', 'paid-memberships-pro' );
										}
										$expiration_text .= '</p>';
										echo wp_kses_post( apply_filters( 'pmpro_account_membership_expiration_text', $expiration_text, $level ) );
									?>
								</td>
							</tr>
							<?php } ?>
						<?php } ?>
					</tbody>
				</table>
				<?php //Todo: If there are multiple levels defined that aren't all in the same group defined as upgrades/downgrades ?>
				<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_actionlinks' ) ); ?>">
					<a id="pmpro_actionlink-levels" href="<?php echo esc_url( pmpro_url( "levels" ) ) ?>"><?php esc_html_e("View all Membership Options", 'paid-memberships-pro' );?></a>
				</div>

			</div> <!-- end pmpro_account-membership -->
		<?php } ?>

		<?php if(in_array('profile', $sections)) { ?>
			<div id="pmpro_account-profile" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_box', 'pmpro_account-profile' ) ); ?>">
				<?php
				if ( '' !== $title ) { // Check if title is being forced to not show.
					// If a custom title was not set, use the default. Otherwise, show the custom title.
					?>
					<h2><?php echo esc_html( null === $title ? __( 'My Account', 'paid-memberships-pro' ) : $title ); ?></h2>
					<?php
				}
				wp_get_current_user();
				?>
				<?php if($current_user->user_firstname) { ?>
					<p><?php echo esc_html( $current_user->user_firstname );?> <?php echo esc_html( $current_user->user_lastname );?></p>
				<?php } ?>
				<ul>
					<?php do_action('pmpro_account_bullets_top');?>
					<li><strong><?php esc_html_e("Username", 'paid-memberships-pro' );?>:</strong> <?php echo esc_html( $current_user->user_login ); ?></li>
					<li><strong><?php esc_html_e("Email", 'paid-memberships-pro' );?>:</strong> <?php echo esc_html( $current_user->user_email ); ?></li>
					<?php do_action('pmpro_account_bullets_bottom');?>
				</ul>
				<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_actionlinks' ) ); ?>">
					<?php
						// Get the edit profile and change password links if 'Member Profile Edit Page' is set.
						if ( ! empty( pmpro_getOption( 'member_profile_edit_page_id' ) ) ) {
							$edit_profile_url = pmpro_url( 'member_profile_edit' );
							$change_password_url = add_query_arg( 'view', 'change-password', pmpro_url( 'member_profile_edit' ) );
						} elseif ( ! pmpro_block_dashboard() ) {
							$edit_profile_url = admin_url( 'profile.php' );
							$change_password_url = admin_url( 'profile.php' );
						}

						// Build the links to return.
						$pmpro_profile_action_links = array();
						if ( ! empty( $edit_profile_url) ) {
							$pmpro_profile_action_links['edit-profile'] = sprintf( '<a id="pmpro_actionlink-profile" href="%s">%s</a>', esc_url( $edit_profile_url ), esc_html__( 'Edit Profile', 'paid-memberships-pro' ) );
						}

						if ( ! empty( $change_password_url ) ) {
							$pmpro_profile_action_links['change-password'] = sprintf( '<a id="pmpro_actionlink-change-password" href="%s">%s</a>', esc_url( $change_password_url ), esc_html__( 'Change Password', 'paid-memberships-pro' ) );
						}

						$pmpro_profile_action_links['logout'] = sprintf( '<a id="pmpro_actionlink-logout" href="%s">%s</a>', esc_url( wp_logout_url() ), esc_html__( 'Log Out', 'paid-memberships-pro' ) );

						$pmpro_profile_action_links = apply_filters( 'pmpro_account_profile_action_links', $pmpro_profile_action_links );

						$allowed_html = array(
							'a' => array (
								'class' => array(),
								'href' => array(),
								'id' => array(),
								'target' => array(),
								'title' => array(),
							),
						);
						echo wp_kses( implode( pmpro_actions_nav_separator(), $pmpro_profile_action_links ), $allowed_html );
					?>
				</div>
			</div> <!-- end pmpro_account-profile -->
		<?php } ?>

		<?php if(in_array('invoices', $sections) && !empty($invoices)) { ?>
		<div id="pmpro_account-invoices" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_box', 'pmpro_account-invoices' ) ); ?>">
			<?php
			if ( '' !== $title ) { // Check if title is being forced to not show.
				// If a custom title was not set, use the default. Otherwise, show the custom title.
				?>
				<h2><?php echo esc_html( null === $title ? __( 'Past Invoices', 'paid-memberships-pro' ) : $title ); ?></h2>
				<?php
			}
			?>
			<table class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_table' ) ); ?>" width="100%" cellpadding="0" cellspacing="0" border="0">
				<thead>
					<tr>
						<th><?php esc_html_e("Date", 'paid-memberships-pro' ); ?></th>
						<th><?php esc_html_e("Level", 'paid-memberships-pro' ); ?></th>
						<th><?php esc_html_e("Amount", 'paid-memberships-pro' ); ?></th>
						<th><?php esc_html_e("Status", 'paid-memberships-pro'); ?></th>
					</tr>
				</thead>
				<tbody>
				<?php
					$count = 0;
					foreach($invoices as $invoice)
					{
						if($count++ > 4)
							break;

						//get an member order object
						$invoice_id = $invoice->id;
						$invoice = new MemberOrder;
						$invoice->getMemberOrderByID($invoice_id);
						$invoice->getMembershipLevel();

						if ( in_array( $invoice->status, array( '', 'success', 'cancelled' ) ) ) {
						    $display_status = esc_html__( 'Paid', 'paid-memberships-pro' );
						} elseif ( $invoice->status == 'pending' ) {
						    // Some Add Ons set status to pending.
						    $display_status = esc_html__( 'Pending', 'paid-memberships-pro' );
						} elseif ( $invoice->status == 'refunded' ) {
						    $display_status = esc_html__( 'Refunded', 'paid-memberships-pro' );
						}
						?>
						<tr id="pmpro_account-invoice-<?php echo esc_attr( $invoice->code ); ?>">
							<td><a href="<?php echo esc_url( pmpro_url( "invoice", "?invoice=" . $invoice->code ) ) ?>"><?php echo esc_html( date_i18n(get_option("date_format"), $invoice->getTimestamp()) )?></a></td>
							<td><?php if(!empty($invoice->membership_level)) echo esc_html( $invoice->membership_level->name ); else echo esc_html__("N/A", 'paid-memberships-pro' );?></td>
							<td><?php
								//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
								echo pmpro_escape_price( pmpro_formatPrice($invoice->total) ); ?></td>
							<td><?php echo esc_html( $display_status ); ?></td>
						</tr>
						<?php
					}
				?>
				</tbody>
			</table>
			<?php if($count == 6) { ?>
				<div class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_actionlinks' ) ); ?>"><a id="pmpro_actionlink-invoices" href="<?php echo esc_url( pmpro_url( "invoice" ) ); ?>"><?php esc_html_e("View All Invoices", 'paid-memberships-pro' );?></a></div>
			<?php } ?>
		</div> <!-- end pmpro_account-invoices -->
		<?php } ?>

		<?php if(in_array('links', $sections) && (has_filter('pmpro_member_links_top') || has_filter('pmpro_member_links_bottom'))) { ?>
		<div id="pmpro_account-links" class="<?php echo esc_attr( pmpro_get_element_class( 'pmpro_box', 'pmpro_account-links' ) ); ?>">
			<?php
			if ( '' !== $title ) { // Check if title is being forced to not show.
				// If a custom title was not set, use the default. Otherwise, show the custom title.
				?>
				<h2><?php echo esc_html( null === $title ? __( 'Member Links', 'paid-memberships-pro' ) : $title ); ?></h2>
				<?php
			}
			?>
			<ul>
				<?php
					do_action("pmpro_member_links_top");
				?>

				<?php
					do_action("pmpro_member_links_bottom");
				?>
			</ul>
		</div> <!-- end pmpro_account-links -->
		<?php } ?>
	</div> <!-- end pmpro_account -->
	<?php

	$content = ob_get_contents();
	ob_end_clean();

	return $content;
}

Code file location:

paid-memberships-pro/paid-memberships-pro/shortcodes/pmpro_account.php

Paid Memberships Pro [pmpro_login] Shortcode

The ‘pmpro_login’ shortcode from the Paid Memberships Pro plugin is utilized to display a login form. It accepts attributes to customize the form’s appearance and behavior. This shortcode can be modified to show or hide a menu and a logout link, and to display the form even if the user is already logged in. By adjusting the ‘display_if_logged_in’, ‘show_menu’, and ‘show_logout_link’ attributes, you can tailor the login form to suit your website’s needs.

Shortcode: [pmpro_login]

Parameters

Here is a list of all possible pmpro_login shortcode parameters and attributes:

  • display_if_logged_in – Determines if the form is visible when the user is logged in.
  • show_menu – Controls the visibility of the menu in the login form.
  • show_logout_link – Decides whether to display a logout link in the form.
  • location – Specifies the location where the shortcode is used.

Examples and Usage

Basic example – Displays a login form with a logout link and menu, visible even if the user is already logged in:

[pmpro_login]

Advanced examples

Displays a login form without a logout link or menu, and only visible if the user is not logged in:

[pmpro_login show_menu="no" show_logout_link="no" display_if_logged_in="no"]

Displays a login form with a logout link but without a menu, visible even if the user is already logged in:

[pmpro_login show_menu="no" show_logout_link="yes" display_if_logged_in="yes"]

Displays a login form with a menu but without a logout link, and only visible if the user is not logged in:

[pmpro_login show_menu="yes" show_logout_link="no" display_if_logged_in="no"]

PHP Function Code

In case you have difficulties debugging what causing issues with [pmpro_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pmpro_login', 'pmpro_shortcode_login' );

Shortcode PHP function:

function pmpro_shortcode_login( $atts, $content=null, $code='' ) {
	// $atts    ::= array of attributes
	// $content ::= text within enclosing form of shortcode element
	// $code    ::= the shortcode found, when == callback name
	// examples: [pmpro_login show_menu="1"]

	extract( shortcode_atts( array(
		'display_if_logged_in' => true,
		'show_menu' => true,
		'show_logout_link' => true,
		'location' => 'shortcode'
	), $atts ) );

	// Turn 0's into falses.
	if ( $display_if_logged_in === '0' || $display_if_logged_in === 'false' || $display_if_logged_in === 'no' ) {
		$display_if_logged_in = false;
	} else {
		$display_if_logged_in = true;
	}

	if ( $show_menu === '0' || $show_menu === 'false' || $show_menu === 'no' ){
		$show_menu = false;
	} else {
		$show_menu = true;
	}

	if ( $show_logout_link === '0' || $show_logout_link === 'false' || $show_logout_link === 'no' ) {
		$show_logout_link = false;
	} else {
		$show_logout_link = true;
	}

	// Display the login form using shortcode attributes.
	return pmpro_login_forms_handler( $show_menu, $show_logout_link, $display_if_logged_in, $location, false );	
}

Code file location:

paid-memberships-pro/paid-memberships-pro/shortcodes/pmpro_login.php

Paid Memberships Pro [pmpro_member] Shortcode

The Paid Memberships Pro shortcode, ‘pmpro_member’, retrieves and displays specific user membership data. It accepts attributes like ‘user_id’ and ‘field’. The ‘field’ attribute is required and corresponds to the user data you want to display. This can be membership details, user meta fields, user column fields, or other specific data like avatar, level cost, or next payment date. The shortcode checks the type of data to format it correctly, especially for date and price fields. It also handles arrays and user fields with multiple options. The output is then filtered and returned for display.

Shortcode: [pmpro_member]

Parameters

Here is a list of all possible pmpro_member shortcode parameters and attributes:

  • user_id – The ID of the user whose membership information is to be displayed.
  • field – The specific membership data to be shown, such as ‘membership_name’, ‘membership_enddate’, ‘bfirstname’, etc.

Examples and Usage

Basic example – Display the last name of the current user

[pmpro_member field='last_name']

Advanced examples

Displaying the membership level name for a specific user by referencing the user ID.

[pmpro_member user_id=2 field='membership_name']

Displaying the next payment date for a specific member.

[pmpro_member user_id=2 field='next_payment_date']

Using the shortcode to display the cost of the membership level for a specific user.

[pmpro_member user_id=2 field='level_cost']

Displaying the avatar of a specific user.

[pmpro_member user_id=2 field='avatar']

Displaying the billing amount for the current user’s membership level.

[pmpro_member field='membership_billing_amount']

Displaying the user’s email from the wp_users column.

[pmpro_member field='user_email']

Displaying the user’s registration date in a formatted manner.

[pmpro_member field='user_registered']

Displaying the user’s credit card type stored in the user meta.

[pmpro_member field='CardType']

PHP Function Code

In case you have difficulties debugging what causing issues with [pmpro_member] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('pmpro_member', 'pmpro_member_shortcode');

Shortcode PHP function:

function pmpro_member_shortcode($atts, $content=null, $code='')
{	
	// $atts    ::= array of attributes
	// $content ::= text within enclosing form of shortcode element
	// $code    ::= the shortcode found, when == callback name
	// examples: [pmpro_member field='last_name']
	global $current_user;

	extract(shortcode_atts(array(
		'user_id' => $current_user->ID,
		'field' => NULL
	), $atts));
	
	//Bail if there's no field attribute
	if( empty( $field ) ) {
		esc_html_e( 'The "field" attribute is required in the pmpro_member shortcode.', 'paid-memberships-pro' );
		return;
	}
	
	/*
		- pmpro_next_payment()
		- 
	*/

	//membership level fields
	$pmpro_level_fields = array(
		'membership_id',
		'membership_name',
		'membership_description',
		'membership_confirmation',
		'membership_initial_payment',
		'membership_billing_amount',
		'membership_cycle_number',
		'membership_cycle_period',
		'membership_billing_limit',
		'membership_trial_amount',
		'membership_trial_limit',
		'membership_startdate',
		'membership_enddate',
	);

	//pmpro-related fields stored in user meta
	$pmpro_user_meta_fields = array(
		'bfirstname',
		'blastname',
		'baddress1',
		'baddress2',
		'bcity',
		'bstate',
		'bzipcode',
		'bcountry',
		'bphone',
		'bemail',
		'CardType',
		'AccountNumber',
		'ExpirationMonth',
		'ExpirationYear',
	);

	//fields stored in wp_users column
	$user_column_fields = array(
		'user_login',
		'user_email',
		'user_url',
		'user_registered',
		'display_name',
	);

	//date fields
	$date_fields = array(
		'startdate',
		'enddate',
		'modified',
		'user_registered',
		'next_payment_date',
	);

	//price fields
	$price_fields = array(
		'initial_payment',
		'billing_amount',
		'trial_amount',
	);

	if($field == 'level_cost') {
		$membership_level = pmpro_getMembershipLevelForUser($user_id);
		if( !empty($membership_level ) )
			$r = pmpro_getLevelCost($membership_level, false, true);
		else
			$r = '';
	} elseif($field == 'next_payment_date') {
		//next_payment_date
		$r = pmpro_next_payment($user_id);
	} elseif(in_array( $field, $pmpro_level_fields )) {
		//membership level fields
		$field = str_replace('membership_', '', $field);
		$membership_level = pmpro_getMembershipLevelForUser($user_id);
		if(!empty($membership_level))
			$r = $membership_level->{$field};
		else
			$r = '';
	} elseif(in_array( $field, $pmpro_user_meta_fields )) {
		//pmpro-related fields stored in user meta
		$field = 'pmpro_' . $field;
		$r = get_user_meta($user_id, $field, true);
	} elseif(in_array( $field, $user_column_fields )) {
		//wp_users column
		$user = get_userdata($user_id);
		$r = $user->{$field};
	} elseif( $field == 'avatar' ) {
		// Get the user's avatar.
		$r = get_avatar( $user_id );
	} else {
		//assume user meta
		$r = get_user_meta($user_id, $field, true);
	}

	//Check for dates to reformat them.
	if(in_array( $field, $date_fields )) {
		if(empty($r) || $r == '0000-00-00 00:00:00')
			$r = '';
		elseif(is_numeric($r))
			$r = date_i18n(get_option('date_format'), $r);											//timestamp
		else
			$r = date_i18n(get_option('date_format'), strtotime($r, current_time('timestamp')));	//YYYY-MM-DD/etc format
	}

	//Check for prices to reformat them.
	if(in_array( $field, $price_fields )) {
		if(empty($r) || $r == '0.00')
			$r = '';
		else
			$r = pmpro_escape_price( pmpro_formatPrice($r) );
	}

	// If this is a user field with an associative array of options, get the label(s) for the value(s).
	$r = pmpro_get_label_for_user_field_value( $field, $r );

	//Check for arrays to reformat them.
	if ( is_array( $r ) ) {
		$r = implode( ', ', $r );
	}

	/** 
	 * Filter
	 */
	$r = apply_filters('pmpro_member_shortcode_field', $r, $user_id, $field);

	return $r;
}

Code file location:

paid-memberships-pro/paid-memberships-pro/shortcodes/pmpro_member.php

Paid Memberships Pro [pmpro_member_profile_edit] Shortcode

The ‘pmpro_member_profile_edit’ shortcode from Paid Memberships Pro plugin allows members to edit their profiles. It checks the current view for ‘change-password’. If present, it displays the ‘Change Password’ form. Otherwise, it shows the ‘Member Profile Edit’ form.

Shortcode: [pmpro_member_profile_edit]

Examples and Usage

Basic example – Displaying the member profile edit form without any parameters.

[pmpro_member_profile_edit]

PHP Function Code

In case you have difficulties debugging what causing issues with [pmpro_member_profile_edit] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pmpro_member_profile_edit', 'pmpro_shortcode_member_profile_edit' );

Shortcode PHP function:

function pmpro_shortcode_member_profile_edit( $atts, $content=null, $code='' ) {
	// $content ::= text within enclosing form of shortcode element
	// $code    ::= the shortcode found, when == callback name
	// examples: [pmpro_member_profile_edit]

	ob_start();

	// Get the current action for the view.
	if ( ! empty( $_REQUEST[ 'view' ] ) ) {
		$view = sanitize_text_field( $_REQUEST[ 'view' ] );
	} else {
		$view = NULL;
	}

	if ( ! empty( $view ) && $view == 'change-password' ) {
		// Display the Change Password form.
		pmpro_change_password_form();
	} else {
		// Display the Member Profile Edit form.
		pmpro_member_profile_edit_form();
	}

	$content = ob_get_contents();
	ob_end_clean();

	return $content;
}

Code file location:

paid-memberships-pro/paid-memberships-pro/shortcodes/pmpro_member_profile_edit.php

Conclusion

Now that you’ve learned how to embed the Paid Memberships Pro Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *