wpsharks / s2member-kb

The s2Member® and s2Member® Pro Knowledge Base
9 stars 4 forks source link

s2Member Shortcode Callback Functions #305

Open renzms opened 8 years ago

renzms commented 8 years ago
KB Article Creation Checklist
title: s2Member Shortcode Callback Functions
categories: tutorials
tags: 
author: renzms
github-issue: https://github.com/websharks/s2member-kb/issues/305

There may be times when you would want to use an s2Member shortcode inside PHP code in instances where do_shortcode() may not be applicable or would not parse correctly.

The following is a list of s2Member shortcode callback functions that can be used instead of do_shortcode(). You could use the following, for example, to add a security badge within a customised PHP template for your checkout/registration pages.

s2Member General Features Shortcode Callback Functions

add_shortcode('s2Key', 'c_ws_plugin__s2member_sc_keys::sc_get_key');
add_shortcode('s2Get', 'c_ws_plugin__s2member_sc_gets::sc_get_details');
add_shortcode('s2Eot', 'c_ws_plugin__s2member_sc_eots::sc_eot_details');
add_shortcode('s2File', 'c_ws_plugin__s2member_sc_files::sc_get_file');
add_shortcode('s2Stream', 'c_ws_plugin__s2member_sc_files::sc_get_stream');
add_shortcode('s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('_s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('__s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('___s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('____s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('_____s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('______s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('_______s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('________s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('_________s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('__________s2If', 'c_ws_plugin__s2member_sc_if_conds::sc_if_conditionals');
add_shortcode('s2Member-Profile', 'c_ws_plugin__s2member_sc_profile::sc_profile');
add_shortcode('s2Member-PayPal-Button', 'c_ws_plugin__s2member_sc_paypal_button::sc_paypal_button');
add_shortcode('s2Member-Security-Badge', 'c_ws_plugin__s2member_sc_s_badge::sc_s_badge');

s2Member Pro Features Shortcode Callback Functions

add_shortcode('s2Drip', 'c_ws_plugin__s2member_pro_sc_drip::shortcode');
add_shortcode('s2MOP', 'c_ws_plugin__s2member_pro_sc_mop_vars_notice::shortcode');
add_shortcode('s2MOPNotice', 'c_ws_plugin__s2member_pro_sc_mop_vars_notice::shortcode');
add_shortcode('s2Member-Login', 'c_ws_plugin__s2member_pro_sc_login::shortcode');
add_shortcode('s2Member-Summary', 'c_ws_plugin__s2member_pro_sc_summary::shortcode');
add_shortcode('s2Member-Gift-Codes', 'c_ws_plugin__s2member_pro_sc_gift_codes::shortcode');
add_shortcode('s2Member-List', 'c_ws_plugin__s2member_pro_sc_member_list::shortcode');
add_shortcode('s2Member-List-Search-Box', 'c_ws_plugin__s2member_pro_sc_member_list::s_box_shortcode');

s2Member Pro Payment Gateway Features Shortcode Callback Functions

add_shortcode('s2Member-Pro-Stripe-Form', 'c_ws_plugin__s2member_pro_stripe_form::sc_stripe_form');
add_shortcode('s2Member-Pro-Stripe-xFormOption', 'c_ws_plugin__s2member_pro_stripe_form::sc_stripe_form_option');
add_shortcode ("s2Member-Pro-PayPal-Form", "c_ws_plugin__s2member_pro_paypal_form::sc_paypal_form");
add_shortcode ("s2Member-Pro-PayPal-xFormOption", "c_ws_plugin__s2member_pro_paypal_form::sc_paypal_form_option");
add_shortcode ("s2Member-Pro-ClickBank-Button", "c_ws_plugin__s2member_pro_clickbank_button::sc_clickbank_button");

add_shortcode ("s2Member-Pro-AuthNet-Form", "c_ws_plugin__s2member_pro_authnet_form::sc_authnet_form");
add_shortcode ("s2Member-Pro-AuthNet-xFormOption", "c_ws_plugin__s2member_pro_authnet_form::sc_authnet_form_option");
jaswrks commented 8 years ago

@renzms Great! Now you need to demonstrate how to extract the callback and show an example of how to use it in PHP. Also, provide links to the source code that show which attributes are supported and explain how to find those for each of the callback functions.

You don't need to do this for all of them, just a couple two or three maybe, so people have a sense of how to take advantage of the information provided by this article.

So for instance, I can look at:

add_shortcode('s2Get', 'c_ws_plugin__s2member_sc_gets::sc_get_details');

and determine that c_ws_plugin__s2member_sc_gets::sc_get_details is the callback function. So I can use it in PHP code like this.

<?php
// Requires PHP 5.4 (or higher).
$atts = [
    'user_field' => 'first_name',
];
echo c_ws_plugin__s2member_sc_gets::sc_get_details($atts);

Supported shortcode attributes seen here in the source code.

raamdev commented 8 years ago

@jaswsinc writes...

$atts = [

I suggest NOT using the array shorthand in the examples for this article—not everyone will be running PHP 5.4+ and the array shorthand will break things and cause all sorts of confusion. I suggest using $atts = array( instead.

GhostMech commented 8 years ago

As a PHP developer myself, who has used your plugin on client sites, I would definitely weigh in here: Use the array() syntax.  Not all clients have moved to PHP 5.4 yet.  Most have 5.3 or lesser.

 - A+ and Network+ certified

I am on Elance:  WordPressPHPguy

  From: Raam Dev <notifications@github.com>

To: websharks/s2member-kb s2member-kb@noreply.github.com Sent: Wednesday, June 1, 2016 9:06 AM Subject: Re: [websharks/s2member-kb] s2Member Shortcode Callback Functions (#305)

@jaswsinc writes... $atts = [ I suggest NOT using the array shorthand in the examples for this article—not everyone will be running PHP 5.4+ and the array shorthand will break things and cause all sorts of confusion. I suggest using $atts = array( instead.— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

jaswrks commented 8 years ago

I suggest NOT using the array shorthand in the examples for this article—not everyone will be running PHP 5.4+ and the array shorthand will break things and cause all sorts of confusion. I suggest using $atts = array( instead.

Nah. If it breaks, it breaks. They can upgrade.

I'm not using the old syntax any longer. Support for PHP 5.3 was dropped about 2 years ago, and while s2Member itself is still compatible with those old versions of PHP I'm not going to tailor my code samples for ancient releases.

jaswrks commented 8 years ago

As a PHP developer myself, who has used your plugin on client sites, I would definitely weigh in here: Use the array() syntax.  Not all clients have moved to PHP 5.4 yet.  Most have 5.3 or lesser.

Upgrade them right away! :-)

GhostMech commented 8 years ago

Wow.Have you ever TRIED to get your hosting company to upgrade?  I had to drop a hosting company because they defaulted to SHOWING ALL ERRORS on PHP.   I am not so sure the crowd will back you on this one.

  From: jaswsinc <notifications@github.com>

To: websharks/s2member-kb s2member-kb@noreply.github.com Cc: Gary Howard garyhowardpctech@yahoo.com; Comment comment@noreply.github.com Sent: Wednesday, June 1, 2016 10:02 AM Subject: Re: [websharks/s2member-kb] s2Member Shortcode Callback Functions (#305)

I suggest NOT using the array shorthand in the examples for this article—not everyone will be running PHP 5.4+ and the array shorthand will break things and cause all sorts of confusion. I suggest using $atts = array( instead. Nah. If it breaks, it breaks. They can upgrade.I'm not using the old syntax any longer. Support for PHP 5.3 was dropped about 2 years ago, and while s2Member itself is still compatible with those old versions of PHP I'm not going to tailor my code samples for ancient releases.— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

raamdev commented 8 years ago

@jaswsinc writes...

Nah. If it breaks, it breaks. They can upgrade.

In the context of a KB Article with code examples, what is the goal? To get users to contact their web host and ask them to upgrade PHP? No. The goal is to provide a code example to help explain or demonstrate something in the KB Article. What's the best way to do that without muddying things (i.e., making the KB Article LESS helpful)? The best way to do that is to take into consideration that a lot of readers are going to copy/paste your code. If the code breaks people's sites, then the KB Article failed.

I'd say the goal for a KB Article is to not fail.

s2Member itself is still compatible with those old versions of PHP

As long as that's the case, s2Member KB Articles should be compatible with those old versions of PHP as well. Doing otherwise would be like including screenshots of an old version of s2Member that shows things that no longer exist.

If the code example demonstrates something that requires a newer version of PHP, then that fact should be explicitly mentioned in the KB Article.

renzms commented 8 years ago

You don't need to do this for all of them, just a couple two or three maybe, so people have a sense of how to take advantage of the information provided by this article.

@jaswsinc, Cool, I will add your example as well if you don't mind. ;)

@raamdev gave me another example to use that I tested out for adding in Coupon Codes to display on a template:

echo c_ws_plugin__s2member_pro_sc_gift_codes_in::shortcode(array('discount'=>'*%', 'quantity'=>'*'), '', 's2Member-Gift-Codes'); 
GhostMech commented 8 years ago

Thanks Raam.A point well made.  Most of my clients have NO IDEA what version of PHP they have: that is my job to know that.   If they go in there and start pasting in code, it's my job to fix it but I would prefer to have something like a warning about what they might put in their WP site.So having  a warning(at least) about what version of PHP is needed to run the code could help me advise them or troubleshoot after-the-fact. Just my opinion here, but I see lots of GoDadddy hosting.....grr....behind in versions.

 - A+ and Network+ certified

I am on Elance:  WordPressPHPguy

  From: Raam Dev <notifications@github.com>

To: websharks/s2member-kb s2member-kb@noreply.github.com Cc: Gary Howard garyhowardpctech@yahoo.com; Comment comment@noreply.github.com Sent: Thursday, June 2, 2016 9:33 AM Subject: Re: [websharks/s2member-kb] s2Member Shortcode Callback Functions (#305)

@jaswsinc writes... Nah. If it breaks, it breaks. They can upgrade. In the context of a KB Article with code examples, what is the goal? To get users to contact their web host and ask them to upgrade PHP? No. The goal is to provide a code example to help explain or demonstrate something in the KB Article. What's the best way to do that without muddying things (i.e., making the KB Article LESS helpful)? The best way to do that is to take into consideration that a lot of readers are going to copy/paste your code. If the code breaks people's sites, then the KB Article failed.I'd say the goal for a KB Article is to not fail. s2Member itself is still compatible with those old versions of PHP As long as that's the case, s2Member KB Articles should be compatible with those old versions of PHP as well. Doing otherwise would be like including screenshots of an old version of s2Member that shows things that no longer exist.If the code example demonstrates something that requires a newer version of PHP, then that fact should be explicitly mentioned in the KB Article.— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

jaswrks commented 8 years ago

@raamdev writes...

If the code example demonstrates something that requires a newer version of PHP, then that fact should be explicitly mentioned in the KB Article.

Sigh... I see your point. Thank you.


@renzms I updated the example above here: https://github.com/websharks/s2member-kb/issues/305#issuecomment-222907102


@raamdev writes...

As long as that's the case, s2Member KB Articles should be compatible with those old versions of PHP as well. Doing otherwise would be like including screenshots of an old version of s2Member that shows things that no longer exist.

I'll agree to mark them as requiring a specific version of PHP as a minimum. I see your point on that and I agree that it's better than just tossing up the code sample and not providing any note about what version of PHP it requires.

However, I'm not going to write code samples (or anything else) for PHP < 5.4. As a part of that decision I will also schedule a version bump in the near future so that s2Member itself will be brought up-to-date with the version of PHP that is seen in more recent KBAs.

Keep in mind that as of 2016 only 15% of the sites running s2Member Pro are using < PHP 5.4.