Ask your WordPress questions! Pay money and get answers fast! (more info)

need two simple shortcodes WordPress

  • SOLVED

1) Here's my psuedocode. I want to make a shortcode from it. When I place the shortcode in a page, I want it to print that output.


if rcpga_group_accounts()->members->is_group_owner() && rcp_can_member_cancel()

print this:

<h3>Close your account</h3>If you'd like to close your account and cancel your subscription, <a href="https://www.example.com/members/cancel-membership/">click here</a>. Note that all your current students or group members will no longer be able to access the service.

else if rcpga_group_accounts()->members->is_group_owner() && 'cancelled' === rcp_get_status()

print this:

<h3>Account closed</h3>Your membership has been cancelled. You and your current group members will continue to have access until the end of this month. No further payments will be taken.

else

do nothing




2) Also, another shortcode to print the output of this:


global $user_ID;

if ( rcp_is_active( $user_ID ) && rcp_can_member_cancel( $user_ID ) ) {

echo '<a href="' . rcp_get_member_cancel_url( $user_ID ) . '" title="' . __( 'Cancel your subscription', 'rcp' ) . '">' . __( 'Cancel your subscription', 'rcp' ) . '</a>';

}



look here for further details about how it works.

https://github.com/restrictcontentpro/restrict-content-pro/blob/master/templates/subscription.php

Answers (2)

2017-01-09

PHPSmashCode answers:

Hello,

Try this,

function fnc_myshort_code_1( $atts ) {
if(rcpga_group_accounts()->members->is_group_owner() && rcp_can_member_cancel())
{
$output = "<h3>Close your account</h3>If you'd like to close your account and cancel your subscription, <a href=\"https://www.example.com/members/cancel-membership/\">click here</a>. Note that all your current students or group members will no longer be able to access the service.";
}
else if( rcpga_group_accounts()->members->is_group_owner() && 'cancelled' === rcp_get_status())
{
$output = "<h3>Account closed</h3>Your membership has been cancelled. You and your current group members will continue to have access until the end of this month. No further payments will be taken.";
}
else
{
$output = "";
}

return $output;
}
add_shortcode( 'my-shortcode-1', 'fnc_myshort_code_1' );


function fnc_myshort_code_2( $atts ) {
global $user_ID;

if ( rcp_is_active( $user_ID ) && rcp_can_member_cancel( $user_ID ) ) {
$output = '<a href="' . rcp_get_member_cancel_url( $user_ID ) . '" title="' . __( 'Cancel your subscription', 'rcp' ) . '">' . __( 'Cancel your subscription', 'rcp' ) . '</a>';
}
return $output;
}
add_shortcode( 'my-shortcode-2', 'fnc_myshort_code_2' );

You can paste it in your themes functions.php file or plugin file.

And you can use it like [my-shortcode-1] and [my-shortcode-2] on your pages,

(you can rename the shortcode names from the code as your wish)

I hope this is you are looking for. Let me know if need further help

Regards,
Hariprasad


jimbob comments:

Hello

The first shortcode works fine. Thank you.

But the second one gives me an error. See the attached screenshot.

Could you please look at this code and figure it out?

https://github.com/restrictcontentpro/restrict-content-pro/blob/master/templates/subscription.php

It's supposed to generate a link that allows the user to cancel.


PHPSmashCode comments:

Hi,

The code looks correct. Make sure the user have active subscription and the user can cancel subscription.

For testing, try this for second shortcode

function fnc_myshort_code_2( $atts ) {
global $user_ID;
$output = '';
if ( rcp_is_active( $user_ID ) && rcp_can_member_cancel( $user_ID ) ) {
$output = rcp_get_member_cancel_url( $user_ID );
}
return $output;
}
add_shortcode( 'my-shortcode-2', 'fnc_myshort_code_2' );

Let me know.

2017-01-09

jimbob answers:

ideally give me the code I can paste into pluginception plugin, to create a plugin that generates the shortcodes