Simple Membership Shortcodes

Below, you’ll find a detailed guide on how to add the Simple Membership 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 Simple Membership Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Simple Membership Plugin and the shortcodes it provides:

Plugin Icon
Simple Membership

"Simple Membership is a user-friendly WordPress plugin that manages and controls content access, perfect for membership-based websites. Empower your website with this essential tool."

★★★★✩ (370) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [swpm_registration_form]
  • [swpm_profile_form]
  • [swpm_login_form]
  • [swpm_reset_form]
  • [swpm_payment_button]
  • [swpm_thank_you_page_registration]
  • [swpm_show_expiry_date]
  • [swpm_mini_login]
  • [swpm_paypal_subscription_cancel_link]
  • [swpm_stripe_subscription_cancel_link]

Simple Membership [swpm_registration_form] Shortcode

The Simple Membership plugin shortcode, “swpm_registration_form”, generates a registration form. This form is customizable based on membership levels. The shortcode initiates by triggering the ‘swpm_shortcode_registration_form_start’ action hook. If a successful submission message is detected, it is returned and the function ends. Otherwise, it checks if free membership is enabled and retrieves the corresponding membership level. The form is then generated based on the level. The function ends by triggering the ‘swpm_shortcode_registration_form_end’ action hook.

Shortcode: [swpm_registration_form]

Parameters

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

  • level – specifies the membership level for the registration form

Examples and Usage

Basic example – A basic usage of the shortcode for the registration form of the Simple Membership plugin. This will display the default registration form.

[swpm_registration_form /]

Advanced examples

Using the shortcode to display a registration form for a specific membership level. The membership level is defined by the ‘level’ attribute. In this example, the membership level ID is 2.

[swpm_registration_form level=2 /]

Using the shortcode to display a registration form for a specific membership level and triggering custom action hooks at the start and end of the form. The action hooks ‘custom_start_hook’ and ‘custom_end_hook’ need to be defined in your functions.php or a custom plugin.

add_action('swpm_shortcode_registration_form_start', 'custom_start_hook');
add_action('swpm_shortcode_registration_form_end', 'custom_end_hook');
[swpm_registration_form level=2 /]

PHP Function Code

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

Shortcode line:

add_shortcode("swpm_registration_form", array(&$this, 'registration_form'));

Shortcode PHP function:

function registration_form($atts) {
        //Trigger action hook
        do_action( 'swpm_shortcode_registration_form_start', $atts );

        $output = "";
        
        //Check if the form has been submitted and there is a success message.
        $any_notice_output = $this->capture_any_notice_output();
        if( !empty( $any_notice_output ) && $this->execution_success_notice ){
            //The registration form execution was a success. Return the success notice output string (it will be used with the shortcode output).
            return $any_notice_output;
        }
        
        $is_free = SwpmSettings::get_instance()->get_value('enable-free-membership');
        $free_level = absint(SwpmSettings::get_instance()->get_value('free-membership-id'));
        $level = isset($atts['level']) ? absint($atts['level']) : ($is_free ? $free_level : null);
        
        $output .= $any_notice_output;
        $output .= SwpmFrontRegistration::get_instance()->regigstration_ui($level);

        //Trigger action hook
        do_action( 'swpm_shortcode_registration_form_end', $atts );
        return $output;
    }

Code file location:

simple-membership/simple-membership/classes/class.simple-wp-membership.php

Simple Membership [swpm_profile_form] Shortcode

The Simple Membership plugin’s shortcode, ‘swpm_profile_form’, is utilized to display a member’s profile form. The shortcode checks if a member is logged in. If so, it loads the ‘edit.php’ template. If not, it displays a ‘not logged in’ message.

Shortcode: [swpm_profile_form]

Examples and Usage

Basic example – Display the profile form of the currently logged-in user.

[swpm_profile_form]

PHP Function Code

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

Shortcode line:

add_shortcode('swpm_profile_form', array(&$this, 'profile_form'));

Shortcode PHP function:

function profile_form() {
        $output = '';
        $auth = SwpmAuth::get_instance();
        $any_notice_output = $this->capture_any_notice_output();
        if ($auth->is_logged_in()) {
            $override_out = apply_filters('swpm_profile_form_override', '');
            if (!empty($override_out)) {
                return $override_out;
            }
            ob_start();
            echo $any_notice_output;//Include any output from the execution (for showing output inside the shortcode)
            //Load the edit profile template
            SwpmUtilsTemplate::swpm_load_template('edit.php', false);
            return ob_get_clean();
        }
        //User is not logged into the site. Show appropriate message.
        $output .= '<div class="swpm_profile_not_logged_in_msg">';
        $output .= SwpmUtils::_('You are not logged in.');
        $output .= '</div>';
        return $output;
    }

Code file location:

simple-membership/simple-membership/classes/class.simple-wp-membership.php

Simple Membership [swpm_login_form] Shortcode

The Simple Membership plugin shortcode ‘swpm_login_form’ is designed to manage the login process. It checks if a user is logged in and loads the appropriate template. If the user is logged in, it loads the ‘loggedin.php’ template. If not, it loads the ‘login.php’ template. It also includes a password visibility toggle option for the login form.

Shortcode: [swpm_login_form]

Examples and Usage

Basic example – A simple usage of the ‘swpm_login_form’ shortcode without any additional parameters. This will display the login form for the Simple Membership plugin.

[swpm_login_form]

PHP Function Code

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

Shortcode line:

add_shortcode('swpm_login_form', array(&$this, 'login'));

Shortcode PHP function:

function login() {
        ob_start();
        $auth = SwpmAuth::get_instance();
        if ($auth->is_logged_in()) {
            //Load the template for logged-in member
            SwpmUtilsTemplate::swpm_load_template('loggedin.php', false);
        } else {
            //Load JS only if option is set
            $display_password_toggle = SwpmSettings::get_instance()->get_value('password-visibility-login-form');
            if ( !empty( $display_password_toggle ) ){
                wp_enqueue_script('swpm.password-toggle');
            }
            //Load the login widget template
            SwpmUtilsTemplate::swpm_load_template('login.php', false);
        }
        return ob_get_clean();
    }

Code file location:

simple-membership/simple-membership/classes/class.simple-wp-membership.php

Simple Membership [swpm_reset_form] Shortcode

The Simple Membership plugin shortcode ‘swpm_reset_form’ is used to reset a user’s password. This shortcode checks if a form has been submitted and generates a success message. If the ‘swpm-reset-using-link’ action is detected, it loads the reset password template. Otherwise, it loads the forgot password template.

Shortcode: [swpm_reset_form]

Examples and Usage

Basic example – A fundamental usage of the ‘swpm_reset_form’ shortcode. This shortcode doesn’t require any parameters and will display the default reset password form.

[swpm_reset_form]

PHP Function Code

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

Shortcode line:

add_shortcode('swpm_reset_form', array(&$this, 'reset'));

Shortcode PHP function:

function reset() {        
        //Check if the form has been submitted and there is a success message.
        $any_notice_output = $this->capture_any_notice_output();
        if( !empty( $any_notice_output ) && $this->success_notice_pw_reset ){
            //The password reset form execution was a success. Return the success notice output string (it will be used with the shortcode output).
            return $any_notice_output;
        }        

        if( isset( $_GET["action"]) && $_GET["action"] == "swpm-reset-using-link" ) {
            ob_start();
            echo $any_notice_output;//Include any output from the execution (for showing output inside the shortcode)
            //Load the reset password template
            SwpmUtilsTemplate::swpm_load_template('reset_password_using_link.php', false);
            return ob_get_clean();
        }
        else {
            ob_start();
            echo $any_notice_output;//Include any output from the execution (for showing output inside the shortcode)
            //Load the forgot password template
            SwpmUtilsTemplate::swpm_load_template('forgot_password.php', false);
            return ob_get_clean();
        }
    }

Code file location:

simple-membership/simple-membership/classes/class.simple-wp-membership.php

Simple Membership [swpm_payment_button] Shortcode

The Simple Membership plugin shortcode, ‘swpm_payment_button’, generates a payment button. It accepts parameters like ‘id’, ‘button_text’, ‘new_window’, and ‘class’. If the ‘id’ is not specified, it returns an error message. The shortcode also includes views from different payment gateways like PayPal, Stripe, Braintree. The payment button generated depends on the ‘button_type’ specified in the post meta of the button id.

Shortcode: [swpm_payment_button]

Parameters

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

  • id – The unique ID of the payment button.
  • button_text – Customizes the text displayed on the payment button.
  • new_window – Determines if payment page opens in a new window.
  • class – Adds a custom CSS class to the payment button.

Examples and Usage

Basic example – Utilizes the shortcode to display a payment button by referencing the button’s ID.

[swpm_payment_button id=1 /]

Advanced examples

Using the shortcode to display a payment button by referencing the button’s ID and customizing the button text. This allows you to specify the text that will be displayed on the button.

[swpm_payment_button id=1 button_text="Buy Now" /]

Using the shortcode to display a payment button in a new window. This can be useful if you want the payment process to occur in a separate window.

[swpm_payment_button id=1 new_window=true /]

Using the shortcode to display a payment button with a custom CSS class. This allows you to apply your own styling to the button.

[swpm_payment_button id=1 class="custom-class" /]

Combining all the parameters to customize the payment button according to your needs.

[swpm_payment_button id=1 button_text="Buy Now" new_window=true class="custom-class" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'swpm_payment_button', array( &$this, 'swpm_payment_button_sc' ) );

Shortcode PHP function:

function swpm_payment_button_sc( $args ) {
		extract(
			shortcode_atts(
				array(
					'id'          => '',
					'button_text' => '',
					'new_window'  => '',
					'class'       => '',
				),
				$args
			)
		);

		if ( empty( $id ) ) {
			return '<p class="swpm-red-box">Error! You must specify a button ID with this shortcode. Check the usage documentation.</p>';
		}

                //Sanitize the arguments.
                $args = array_map( 'esc_attr', $args );
                        
		$button_id = $id;
		//$button = get_post($button_id); //Retrieve the CPT for this button
		$button_type = get_post_meta( $button_id, 'button_type', true );
		if ( empty( $button_type ) ) {
			$error_msg  = '<p class="swpm-red-box">';
			$error_msg .= 'Error! The button ID (' . $button_id . ') you specified in the shortcode does not exist. You may have deleted this payment button. ';
			$error_msg .= 'Go to the Manage Payment Buttons interface then copy and paste the correct button ID in the shortcode.';
			$error_msg .= '</p>';
			return $error_msg;
		}

		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/paypal_button_shortcode_view.php' );
		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/stripe_button_shortcode_view.php' );
		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/stripe_sca_button_shortcode_view.php' );
		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/braintree_button_shortcode_view.php' );
		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/paypal_smart_checkout_button_shortcode_view.php' );
		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/paypal_buy_now_new_button_shortcode_view.php' );
		include_once( SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/payment-gateway/paypal_subscription_new_button_shortcode_view.php' );

		$button_code = '';
		$button_code = apply_filters( 'swpm_payment_button_shortcode_for_' . $button_type, $button_code, $args );

		$output  = '';
		$output .= '<div class="swpm-payment-button">' . $button_code . '</div>';

		return $output;
	}

Code file location:

simple-membership/simple-membership/classes/shortcode-related/class.swpm-shortcodes-handler.php

Simple Membership [swpm_thank_you_page_registration] Shortcode

The Simple Membership plugin shortcode ‘swpm_thank_you_page_registration’ is used to handle post-registration tasks. It checks if a user is logged in, updates their membership profile, and provides a link to complete registration. If the user isn’t logged in, it prompts them to check back later after their payment is processed.

Shortcode: [swpm_thank_you_page_registration]

Examples and Usage

Basic example – Show a thank you page after registration

[swpm_thank_you_page_registration /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'swpm_thank_you_page_registration', array( &$this, 'swpm_ty_page_rego_sc' ) );

Shortcode PHP function:

function swpm_ty_page_rego_sc( $args ) {
		$output   = '';
		$settings = SwpmSettings::get_instance();

		//If user is logged in then the purchase will be applied to the existing profile
		if ( SwpmMemberUtils::is_member_logged_in() ) {
			$username = SwpmMemberUtils::get_logged_in_members_username();
			$output  .= '<div class="swpm-ty-page-registration-logged-in swpm-yellow-box">';
			$output  .= '<p>' . SwpmUtils::_( 'Your membership profile will be updated to reflect the payment.' ) . '</p>';
			$output  .= SwpmUtils::_( 'Your profile username: ' ) . $username;
			$output  .= '</div>';
			$output = apply_filters( 'swpm_ty_page_registration_msg_to_logged_in_member', $output );
			return $output;
		}

		$output .= '<div class="swpm-ty-page-registration">';
		$member_data = SwpmUtils::get_incomplete_paid_member_info_by_ip();
		if ( $member_data ) {
			//Found a member profile record for this IP that needs to be completed
			$reg_page_url      = $settings->get_value( 'registration-page-url' );
			$rego_complete_url = add_query_arg(
				array(
					'member_id' => $member_data->member_id,
					'code'      => $member_data->reg_code,
				),
				$reg_page_url
			);
			$output .= '<div class="swpm-ty-page-registration-link swpm-yellow-box">';
			$output .= '<p>' . SwpmUtils::_( 'Click on the following link to complete the registration.' ) . '</p>';
			$output .= '<p><a href="' . $rego_complete_url . '">' . SwpmUtils::_( 'Click here to complete your paid registration' ) . '</a></p>';
			$output .= '</div>';
			//Allow addons to modify the output
			$output = apply_filters( 'swpm_ty_page_registration_msg_with_link', $output, $rego_complete_url );
		} else {
			//Nothing found. Check again later.
			$output .= '<div class="swpm-ty-page-registration-link swpm-yellow-box">';
			$output .= SwpmUtils::_( 'If you have just made a membership payment then your payment is yet to be processed. Please check back in a few minutes. An email will be sent to you with the details shortly.' );
			$output .= '</div>';
			//Allow addons to modify the output
			$output = apply_filters( 'swpm_ty_page_registration_msg_no_link', $output );
		}

		$output .= '</div>'; //end of .swpm-ty-page-registration

		$output = apply_filters( 'swpm_ty_page_registration_output', $output );
		return $output;
	}

Code file location:

simple-membership/simple-membership/classes/shortcode-related/class.swpm-shortcodes-handler.php

Simple Membership [swpm_show_expiry_date] Shortcode

The Simple Membership plugin shortcode ‘swpm_show_expiry_date’ is designed to display the expiry date of a logged-in member. When used, it checks if a member is logged in. If true, it retrieves and displays the expiry date. If false, it returns a message indicating the user is not logged in.

Shortcode: [swpm_show_expiry_date]

Examples and Usage

Basic Example – Displays the expiry date of the current logged-in member using the ‘swpm_show_expiry_date’ shortcode.

[swpm_show_expiry_date /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'swpm_show_expiry_date', array( &$this, 'swpm_show_expiry_date_sc' ) );

Shortcode PHP function:

function swpm_show_expiry_date_sc( $args ) {
		$output = '<div class="swpm-show-expiry-date">';
		if ( SwpmMemberUtils::is_member_logged_in() ) {
			$auth        = SwpmAuth::get_instance();
			$expiry_date = $auth->get_expire_date();
			$output     .= SwpmUtils::_( 'Expiry: ' ) . $expiry_date;
		} else {
			$output .= SwpmUtils::_( 'You are not logged-in as a member' );
		}
		$output .= '</div>';
		return $output;
	}

Code file location:

simple-membership/simple-membership/classes/shortcode-related/class.swpm-shortcodes-handler.php

Simple Membership [swpm_mini_login] Shortcode

The Simple Membership plugin shortcode ‘swpm_mini_login’ displays a compact login form. When a user is logged in, it shows the username, a link to the profile, and a logout option. If a user isn’t logged in, it displays a ‘Login Here’ link and a ‘Not a member? Join Now’ link. The login and join links can be customized in the plugin settings.

Shortcode: [swpm_mini_login]

Examples and Usage

Basic example – The shortcode ‘swpm_mini_login’ is used to display a mini login form. If the user is logged in, it will display the username, profile link, and logout link. If the user is not logged in, it will display a login link and a ‘join now’ link.

[swpm_mini_login /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'swpm_mini_login', array( &$this, 'swpm_show_mini_login_sc' ) );

Shortcode PHP function:

function swpm_show_mini_login_sc( $args ) {

		$login_page_url   = SwpmSettings::get_instance()->get_value( 'login-page-url' );
		$join_page_url    = SwpmSettings::get_instance()->get_value( 'join-us-page-url' );
		$profile_page_url = SwpmSettings::get_instance()->get_value( 'profile-page-url' );
		$logout_url       = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '?swpm-logout=true';

		$filtered_login_url = apply_filters( 'swpm_get_login_link_url', $login_page_url ); //Addons can override the login URL value using this filter.

		$output = '<div class="swpm_mini_login_wrapper">';

		//Check if the user is logged in or not
		$auth = SwpmAuth::get_instance();
		if ( $auth->is_logged_in() ) {
			//User is logged in
			$username = $auth->get( 'user_name' );
			$output  .= '<span class="swpm_mini_login_label">' . SwpmUtils::_( 'Logged in as: ' ) . '</span>';
			$output  .= '<span class="swpm_mini_login_username">' . $username . '</span>';
			$output  .= '<span class="swpm_mini_login_profile"> | <a href="' . $profile_page_url . '">' . SwpmUtils::_( 'Profile' ) . '</a></span>';
			$output  .= '<span class="swpm_mini_login_logout"> | <a href="' . $logout_url . '">' . SwpmUtils::_( 'Logout' ) . '</a></span>';
		} else {
			//User not logged in.
			$output .= '<span class="swpm_mini_login_login_here"><a href="' . $filtered_login_url . '">' . SwpmUtils::_( 'Login Here' ) . '</a></span>';
			$output .= '<span class="swpm_mini_login_no_membership"> | ' . SwpmUtils::_( 'Not a member? ' ) . '</span>';
			$output .= '<span class="swpm_mini_login_join_now"><a href="' . $join_page_url . '">' . SwpmUtils::_( 'Join Now' ) . '</a></span>';
		}

		$output .= '</div>';

		$output = apply_filters( 'swpm_mini_login_output', $output );

		return $output;
	}

Code file location:

simple-membership/simple-membership/classes/shortcode-related/class.swpm-shortcodes-handler.php

Simple Membership [swpm_paypal_subscription_cancel_link] Shortcode

The Simple Membership plugin shortcode ‘[swpm_paypal_subscription_cancel_link]’ allows members to cancel their PayPal subscription. It generates a link that directs to PayPal’s subscription cancellation page. The shortcode requires a ‘merchant_id’ parameter to function properly. It can also accept parameters like ‘anchor_text’, ‘new_window’, and ‘css_class’ for customization. When not logged in as a member, it returns a message stating ‘You are not logged in as a member.’

Shortcode: [swpm_paypal_subscription_cancel_link]

Parameters

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

  • merchant_id – the secure PayPal merchant ID for your account
  • anchor_text – the text to be displayed on the subscription cancellation link
  • new_window – opens the cancellation link in a new browser tab when set
  • css_class – applies a specific CSS class to the cancellation link

Examples and Usage

Basic example – A simple shortcode usage to cancel PayPal subscription by providing the merchant ID.

[swpm_paypal_subscription_cancel_link merchant_id="your_merchant_id"]

Advanced examples

Using the shortcode to cancel PayPal subscription with a custom anchor text. It serves as an alternative text for the default ‘Unsubscribe from PayPal’ text.

[swpm_paypal_subscription_cancel_link merchant_id="your_merchant_id" anchor_text="Cancel My Subscription"]

Using the shortcode with a custom CSS class. This allows you to style the link according to your site’s theme.

[swpm_paypal_subscription_cancel_link merchant_id="your_merchant_id" css_class="your_css_class"]

Using the shortcode with a new window parameter. This will open the PayPal page in a new browser tab or window when the link is clicked.

[swpm_paypal_subscription_cancel_link merchant_id="your_merchant_id" new_window="yes"]

Using the shortcode with multiple parameters. This will create a custom link with a specific CSS class that opens in a new window and has a custom anchor text.

[swpm_paypal_subscription_cancel_link merchant_id="your_merchant_id" anchor_text="Cancel My Subscription" new_window="yes" css_class="your_css_class"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'swpm_paypal_subscription_cancel_link', array( &$this, 'swpm_pp_cancel_subs_link_sc' ) );

Shortcode PHP function:

function swpm_pp_cancel_subs_link_sc( $args ) {
                //Shortcode parameters: ['anchor_text'], ['merchant_id']

		extract(
			shortcode_atts(
				array(
					'merchant_id' => '',
					'anchor_text' => '',
                                        'new_window' => '',
                                        'css_class' => '',
				),
				$args
			)
		);

		if ( empty( $merchant_id ) ) {
			return '<p class="swpm-red-box">Error! You need to specify your secure PayPal merchant ID in the shortcode using the "merchant_id" parameter.</p>';
		}

		$output   = '';
		$settings = SwpmSettings::get_instance();

		//Check if the member is logged-in
		if ( SwpmMemberUtils::is_member_logged_in() ) {
			$user_id = SwpmMemberUtils::get_logged_in_members_id();
		}

		if ( ! empty( $user_id ) ) {
			//The user is logged-in

                        //Set the default window target (if it is set via the shortcode).
                        if ( empty( $new_window ) ) {
                            $window_target = '';
                        } else {
                            $window_target = ' target="_blank"';
                        }

                        //Set the CSS class (if it is set via the shortcode).
                        if ( empty( $css_class ) ) {
                            $link_css_class = '';
                        } else {
                            $link_css_class = ' class="' . $css_class . '"';
                        }

			//Set the default anchor text (if one is provided via the shortcode).
			if ( empty( $anchor_text ) ) {
				$anchor_text = SwpmUtils::_( 'Unsubscribe from PayPal' );
			}

			$output .= '<div class="swpm-paypal-subscription-cancel-link">';
			$sandbox_enabled = $settings->get_value( 'enable-sandbox-testing' );
			if ( $sandbox_enabled ) {
				//Sandbox mode
				$output .= '<a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '" _fcksavedurl="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '" '. $window_target . esc_attr($link_css_class) .'>';
				$output .= $anchor_text;
				$output .= '</a>';
			} else {
				//Live mode
				$output .= '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '" _fcksavedurl="https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=' . $merchant_id . '" '.$window_target . esc_attr($link_css_class) .'>';
				$output .= $anchor_text;
				$output .= '</a>';
			}
			$output .= '</div>';

		} else {
			//The user is NOT logged-in
			$output .= '<p>' . SwpmUtils::_( 'You are not logged-in as a member' ) . '</p>';
		}
		return $output;
	}

Code file location:

simple-membership/simple-membership/classes/shortcode-related/class.swpm-shortcodes-handler.php

Simple Membership [swpm_stripe_subscription_cancel_link] Shortcode

The Simple Membership Plugin shortcode, ‘swpm_stripe_subscription_cancel_link’, allows members to cancel their active Stripe subscriptions. This shortcode only works if a member is logged in and has an active subscription.

Shortcode: [swpm_stripe_subscription_cancel_link]

Examples and Usage

Basic example – This shortcode generates a link that allows a logged-in member to cancel their Stripe subscription. The ‘anchor_text’ parameter is used to set the text of the link.

[swpm_stripe_subscription_cancel_link anchor_text="Cancel Subscription"]

Advanced examples

Using the shortcode to display a custom cancellation link text based on the logged-in member’s subscription status. If the member has no active subscriptions, the link will not be displayed.

[swpm_stripe_subscription_cancel_link anchor_text="Click here to cancel your active subscription"]

Another advanced usage could be to use the shortcode within a conditional statement in a page template. This would allow you to display different content based on whether the user has an active subscription.

<?php
if ( shortcode_exists( 'swpm_stripe_subscription_cancel_link' ) ) {
    echo do_shortcode( '[swpm_stripe_subscription_cancel_link anchor_text="Cancel your subscription"]' );
} else {
    echo 'Please log in to manage your subscription.';
}
?>

PHP Function Code

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

Shortcode line:

add_shortcode( 'swpm_stripe_subscription_cancel_link', array( $this, 'swpm_stripe_cancel_subs_link_sc' ) );

Shortcode PHP function:

function swpm_stripe_cancel_subs_link_sc( $args ) {
                //Shortcode parameters: ['anchor_text']

		if ( ! SwpmMemberUtils::is_member_logged_in() ) {
			//member not logged in
			return SwpmUtils::_( 'You are not logged-in as a member' );
		}
		$member_id = SwpmMemberUtils::get_logged_in_members_id();

		$subs = new SWPM_Member_Subscriptions( $member_id );

		if ( empty( $subs->get_active_subs_count() ) ) {
			//no active subscriptions found
			return SwpmUtils::_( 'No active subscriptions' );
		}

                $output = $subs->get_stripe_subs_cancel_url($args, false);

		return $output;
	}

Code file location:

simple-membership/simple-membership/classes/shortcode-related/class.swpm-shortcodes-handler.php

Conclusion

Now that you’ve learned how to embed the Simple Membership 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 *