“,
‚button_text‘ => “,
’new_window‘ => “,
‚class‘ => “,
),
$args
)
);
if ( empty( $id ) ) {
return ‚
Error! You must specify a button ID with this shortcode. Check the usage documentation.
‚;
}
//Add a quick escaping to the shortcode 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 = ‚
‚;
$error_msg .= ‚Error! The button ID (‚ . esc_attr($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 .= ‚
‚;
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 .= ‚
‚;
return $output;
}
public 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 .= ‚
$output .= ‚
‚ . __( ‚Your membership profile will be updated to reflect the payment.‘, ’simple-membership‘ ) . ‚
‚;
$output .= __( ‚Your profile username: ‚, ’simple-membership‘ ) . esc_attr($username);
$output .= ‚
‚;
$output = apply_filters( ’swpm_ty_page_registration_msg_to_logged_in_member‘, $output );
return $output;
}
//If user is not-logged in then lets see if there is a pending registration that needs to be completed.
$output .= ‚
$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 .= ‚
$output .= ‚
‚ . __( ‚Click on the following link to complete the registration.‘, ’simple-membership‘ ) . ‚
‚;
$output .= ‚
‚ . __( ‚Click here to complete your paid registration‘, ’simple-membership‘ ) . ‚
‚;
$output .= ‚
‚;
//Allow addons to modify the output
$output = apply_filters( ’swpm_ty_page_registration_msg_with_link‘, $output, $rego_complete_url );
} else if ( SwpmMemberUtils::get_user_by_ip_address() ) {
//Found a member profile record for this IP but it is not a pending registration
$output .= ‚
$output .= __( „It looks like you have already completed the registration process. You can now log in to the site and start enjoying your membership benefits.“, „simple-membership“ );
$output .= ‚
‚;
//Allow addons to modify the output
$output = apply_filters( ’swpm_ty_page_registration_msg_found_user_by_ip‘, $output );
} else {
//Nothing found. Check again later.
$output .= ‚
$output .= __( ‚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.‘, ’simple-membership‘ );
$output .= ‚
‚;
//Allow addons to modify the output
$output = apply_filters( ’swpm_ty_page_registration_msg_no_link‘, $output );
}
$output .= ‚
‚; //end of .swpm-ty-page-registration
$output = apply_filters( ’swpm_ty_page_registration_output‘, $output );
return $output;
}
public function swpm_show_expiry_date_sc( $args ) {
$output = ‚
if ( SwpmMemberUtils::is_member_logged_in() ) {
$auth = SwpmAuth::get_instance();
$expiry_date = $auth->get_expire_date();
$output .= __( ‚Expiry: ‚, ’simple-membership‘ ) . esc_attr($expiry_date);
} else {
$output .= __( ‚You are not logged-in as a member‘, ’simple-membership‘ );
}
$output .= ‚
‚;
return $output;
}
public 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.
//Start building the output
$output = ‚
//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‘ );
$mini_login_output_when_logged_in = ‚‚ . __( ‚Logged in as: ‚, ’simple-membership‘) . ‚‚;
$mini_login_output_when_logged_in .= ‚‚ . esc_attr($username) . ‚‚;
$mini_login_output_when_logged_in .= ‚ | ‚ . __( ‚Profile‘, ’simple-membership‘) . ‚‚;
$mini_login_output_when_logged_in .= ‚ | ‚ . __( ‚Logout‘, ’simple-membership‘) . ‚‚;
//Trigger filter to allow addons to modify this output.
$mini_login_output_when_logged_in = apply_filters( ’swpm_mini_login_output_when_logged_in‘, $mini_login_output_when_logged_in );
//Add the logged-in output to the main output
$output .= $mini_login_output_when_logged_in;
} else {
//User is NOT logged-in.
$mini_login_output_when_not_logged = ‚‚ . __( ‚Login Here‘, ’simple-membership‘) . ‚‚;
//Check if the join us link should be hidden
$hide_join_us_link_enabled = SwpmSettings::get_instance()->get_value(‚hide-join-us-link‘);
if (empty($hide_join_us_link_enabled)){
//Show the join us option.
$mini_login_output_when_not_logged .= ‚ | ‚ . __( ‚Not a member? ‚, ’simple-membership‘) . ‚‚;
$mini_login_output_when_not_logged .= ‚‚ . __( ‚Join Now‘, ’simple-membership‘) . ‚‚;
}
//Trigger filter to allow addons to modify this output.
$mini_login_output_when_not_logged = apply_filters( ’swpm_mini_login_output_when_not_logged_in‘, $mini_login_output_when_not_logged );
//Add the not logged-in output to the main output
$output .= $mini_login_output_when_not_logged;
}
$output .= ‚
‚;//end of .swpm_mini_login_wrapper
//Trigger filter to allow addons to modify the final output.
$output = apply_filters( ’swpm_mini_login_output‘, $output );
return $output;
}
public function swpm_stripe_cancel_subs_link_sc( $args ) {
//Shortcode parameters: [‚anchor_text‘]
if ( ! SwpmMemberUtils::is_member_logged_in() ) {
//member not logged in
$error_msg = ‚
‚;
return $error_msg;
}
//Get the member ID
$member_id = SwpmMemberUtils::get_logged_in_members_id();
$subs = (new SWPM_Utils_Subscriptions( $member_id ))->load_stripe_subscriptions();
if ( empty( $subs->get_active_subs_count() ) ) {
//no active subscriptions found
$error_msg = ‚
‚;
return $error_msg;
}
$output = $subs->get_stripe_subs_cancel_url($args, false);
$output = ‚
‚;
return $output;
}
public 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 ‚
Error! You need to specify your secure PayPal merchant ID in the shortcode using the „merchant_id“ parameter.
‚;
}
$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=“‚ . sanitize_html_class($css_class) . ‚“‚;
}
//Set the default anchor text (if one is provided via the shortcode).
if ( empty( $anchor_text ) ) {
$anchor_text = __( ‚Unsubscribe from PayPal‘, ’simple-membership‘ );
}
$output .= ‚
$sandbox_enabled = $settings->get_value( ‚enable-sandbox-testing‘ );
if ( $sandbox_enabled ) {
//Sandbox mode
$output .= ‚‚;
$output .= esc_attr($anchor_text);
$output .= ‚‚;
} else {
//Live mode
$output .= ‚‚;
$output .= esc_attr($anchor_text);
$output .= ‚‚;
}
$output .= ‚
‚;
} else {
//The user is NOT logged-in
$output .= ‚
‚ . __( ‚You are not logged-in as a member.‘, ’simple-membership‘ ) . ‚
‚;
}
return $output;
}
public function swpm_show_subscriptions_and_cancel_link($atts){
$output = “;
$atts = shortcode_atts(array(
’show_all_status‘ => “
), $atts);
if ( ! SwpmMemberUtils::is_member_logged_in() ) {
//member not logged in
return ‚
‚.__( ‚You are not logged-in as a member.‘, ’simple-membership‘ ).‘
‚;
}
//Get the member ID and load subscriptions utils class.
$member_username = SwpmMemberUtils::get_logged_in_members_username();
$member_id = SwpmMemberUtils::get_logged_in_members_id();
//We will use this class to load the curated subscriptions list data so we can use it in this shortcode.
$subscriptions_utils = new SWPM_Utils_Subscriptions( $member_id );
$subscriptions_utils->load_subs_data();
/**
* Display any API key error messages (if subscription exists but api keys are not saved).
* The error message is only shown when the subscription of the corresponding payment gateway is present.
* For example: If there are no stripe sca subscriptions, stripe api error wont be shown.
*/
$any_stripe_api_key_error_msg = $subscriptions_utils->get_any_stripe_sca_api_key_error();
if ( !empty( $any_stripe_api_key_error_msg ) ) {
$output .= ‚
‚. esc_attr($any_stripe_api_key_error_msg) . ‚
‚;
}
$any_paypal_api_key_error_msg = $subscriptions_utils->get_any_paypal_ppcp_api_key_error();
if ( !empty( $any_paypal_api_key_error_msg ) ) {
$output .= ‚
‚. esc_attr($any_paypal_api_key_error_msg) . ‚
‚;
}
//Check if we need to show all subscriptions or just the active ones
$show_all_subscriptions = !empty($atts[’show_all_status‘]) ? true : false;
//Get the list of subscriptions
if ($show_all_subscriptions) {
$subscriptions_list = $subscriptions_utils->get_all_subscriptions();
}else{
$subscriptions_list = $subscriptions_utils->get_active_subscriptions();
}
//Display the list of subscriptions
$output .= ‚
if (count($subscriptions_list)) {
$output .= ‚
‚. __(‚Subscription‘, ’simple-membership‘).‘ | ‚. __(‚Action‘, ’simple-membership‘) .‘ |
---|---|
‚; $output .= ‚ ‚. esc_attr($subscription[‚plan‘]).‘
‚; ‚. __(‚Currently used for your membership access.‘, ’simple-membership‘).‘
‚; |
‚; $output .= SWPM_Utils_Subscriptions::get_cancel_subscription_output($subscription); $output .= ‚ |
‚;
}else{
$output .= ‚
‚.__( ‚Active subscription not detected for the member account with the username: ‚, ’simple-membership‘ ). esc_attr($member_username) . ‚
‚;
}
//This is used to refresh the page so this shortcode is reloaded after a new subscription is added.
//This is needed for the newly created subscription to show up in the list.
$output .= ‚‚;
$output .= ‚
‚;
return $output;
}
}