PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

[Solved] Variables Not Interpreted Correctly in Custom Value

s2Member Plugin. A Membership plugin for WordPress®.

[Solved] Variables Not Interpreted Correctly in Custom Value

Postby angelazou » January 17th, 2012, 3:58 am

I am having a bit difficulty trying to stick some variables into the custom fields.

Code: Select all
[s2Member-Pro-AliPay-Button level="1" ccaps="" desc="A" custom="domain.com|1|$pay|$package|$lang|$email|$pass" ra="550" rp="1" rt="Y" image="default" output="anchor" /]


I tried to use the above code, but all I get in the Alipay button is their literal value

Code: Select all
extra_common_param=domain.com%7C1%7C%24pay%7C%24package%7C%24lang%7C%24email%7C%24pass


Must the attribute values be literal? I really need to save these information dynamically (as I pull them from the form), and custom field is the only way I can do this without too much tweaking (if possible, I'd really prefer not to create and dynamically popular a Pro Form). Where did I go wrong?

Angela

PS: In addition, if the variable contains HTML decoded entities such as %40 (which was originally the @ symbol), would S2member take care of that, or what is the function I should use to get it back to its original value?
Last edited by angelazou on January 26th, 2012, 11:26 pm, edited 1 time in total.
User avatar
angelazou
Registered User
Registered User
 
Posts: 72
Joined: July 14, 2011

Re: Variables Not Interpreted Correctly in Custom Value

Postby angelazou » January 17th, 2012, 11:03 pm

I found that most S2member variables are in the format of %%variable%%, and the lines used to preg_replace them from the original variables. Should I do the same in order to put those values as the custom values?
User avatar
angelazou
Registered User
Registered User
 
Posts: 72
Joined: July 14, 2011

Re: Variables Not Interpreted Correctly in Custom Value

Postby angelazou » January 19th, 2012, 8:31 pm

Help? I really need this last bit to finish the setup...
User avatar
angelazou
Registered User
Registered User
 
Posts: 72
Joined: July 14, 2011

Re: Variables Not Interpreted Correctly in Custom Value

Postby Jason Caldwell » January 19th, 2012, 10:50 pm

Hi there. Thanks for your inquiry.
These variables are not being parsed because they are not wrapped inside PHP tags.
custom="domain.com|1|$pay|$package|$lang|$email|$pass"
In addition, I'm not sure where the value of these variables come from exactly? I'm assuming that you do though. You might take a look at this post for some clarity in this matter. Please note that you might need to seek assistance from a PHP developer to accomplish what you need here.

See: viewtopic.php?f=36&t=1604
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Variables Not Interpreted Correctly in Custom Value

Postby angelazou » January 19th, 2012, 11:12 pm

Actually, I was using Shortcode EXEC PHP plugin to create a shortcode to insert into the page, which looks something like this:

Code: Select all
$pay = $_GET["pay"];
if ($pay == "alipay") {
  $button = [s2Member-Pro-AliPay-Button level="1" ccaps="" desc="A" custom="domain.com|1|$pay|$package|$lang|$email|$pass" ra="550" rp="1" rt="Y" image="default" output="anchor" /]
}

return $button;


There are some issues at the site presently, once it's fixed, I can show you the entire shortcode I used. But I can be very sure that it was running within a PHP environment. I will check out that thread, and see if it can fix the issue.
User avatar
angelazou
Registered User
Registered User
 
Posts: 72
Joined: July 14, 2011

Re: Variables Not Interpreted Correctly in Custom Value

Postby angelazou » January 25th, 2012, 10:33 am

Sorry about the late reply, I lost my database a couple of days ago, I had to rebuild everything again. So the process works like this:
- I set up the buttons matching all the options
- I use _GET to obtain the option settings
- then I use do_shortcode to make the shortcode available

The only culprit I can think of is because I'm doing all of these inside a shortcode function (which is placed on the membership options page). This is my code:
Code: Select all
function confirm_func ($atts) {
   $fn = $_GET['fn'];
   $email = $_GET['email'];
   $domain = $_GET['domain'];
   $package = $_GET['package'];
   $pay = $_GET['pay'];
   $oid = $_GET['oid'];
   $lang = $_GET['lang'];

   if ($pay == 'alipay') {
      switch($package) {
         case 'A':
            $button = do_shortcode('[s2Member-Pro-AliPay-Button level="1" ccaps="" desc="托管套餐A" custom="example.com|" . $fn . "|" . $email . "|" . $domain . "|" . $package . "|" . $pay . "|" . $oid . "|" . $lang ra="550" rp="1" rt="Y" image="default" output="anchor" /]');
            $pack = '托管套餐A';
            break;
         case 'B':
            $button = do_shortcode('[s2Member-Pro-AliPay-Button level="1" ccaps="" desc="托管套餐B" custom="example.com|$fn|$email|$domain|$package|$pay|$oid|$lang" ra="700" rp="1" rt="Y" image="default" output="anchor" /]');
            $pack = '托管套餐B';
            break;
         case 'C':
            $button = do_shortcode('[s2Member-Pro-AliPay-Button level="1" ccaps="" desc="无限托管" custom="example.com|$fn|$email|$domain|$package|$pay|$oid|$lang" ra="999" rp="1" rt="Y" image="default" output="anchor" /]');
            $pack = '无限托管';
            break;
         default:
            $output .= '出错了!';
      }
   } else if ($pay == 'paypal') {
      switch($package) {
         case 'A':
            $button = do_shortcode('[s2Member-PayPal-Button level="1" ccaps="" desc="Shared Plan A" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="example.com|$fn|$email|$domain|$package|$pay|$oid|$lang" ta="0" tp="0" tt="D" ra="65.45" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]');
            $pack = 'Shared Plan A';
            break;
         case 'B':
            $button = do_shortcode('[s2Member-PayPal-Button level="1" ccaps="" desc="Shared Plan B" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="example.com|$fn|$email|$domain|$package|$pay|$oid|$lang" ta="0" tp="0" tt="D" ra="87.45" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]');
            $pack = 'Shared Plan B';
            break;
         case 'C':
            $button = do_shortcode('[s2Member-PayPal-Button level="1" ccaps="" desc="Unlimited Hosting" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="example.com|$fn|$email|$domain|$package|$pay|$oid|$lang" ta="0" tp="0" tt="D" ra="107.25" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]');
            $pack = 'Unlimited Hosting';
            break;
         default:
            $output .= 'Package and Gateway Information Missing. Contact Support';
      }
   }


   if (strpos($_SERVER['REQUEST_URI'], '/zh/') !== false) {
      $output .= '<table><tbody>';
      $output .= '<tr><td>用户ID</td><td>' . $oid . '</td></tr>';
      $output .= '<tr><td>语言</td><td>中文</td></tr>';
      $output .= '<tr><td>套餐</td><td>' . $pack . '</td></tr>';
      $output .= '<tr><td>结算</td><td>' . $button . ' </td></tr>';
      $output .= '</tbody></table>';
   } else {
      $output .= '<table><tbody>';
      $output .= '<tr><td>OID</td><td>' . $oid . '</td></tr>';
      $output .= '<tr><td>Language</td><td>English</td></tr>';
      $output .= '<tr><td>Hosting Plan</td><td>' . $pack . '</td></tr>';
      $output .= '<tr><td>Purchase</td><td>' . $button . '</td></tr>';
      $output .= '</tbody></table>';
   }

   return $output;
}
add_shortcode('confirm', 'confirm_func');


You can see that I tried 2 approaches in putting that data into the button. One is "custom="example.com|" . $fn . "|" . $email . "|" . $domain . "|" . $package . "|" . $pay . "|" . $oid . "|" . $lang" and the other is "custom=example.com|$fn|$email|$domain|$package|$pay|$oid|$lang". Unfortunately, none of them works.
In the first approach, my button link look something like this
Code: Select all
https://www.alipay.com/cooperate/gateway.do?_input_charset=utf-8&body=托管套餐A&extra_common_param=example.com%7C&notify_url=http%3A%2F%2Fexample.com%2F&out_trade_no=4f201de64f3c7%7E1%3A%3A1+Y%7E1%7E120.32.3.116&partner=2088501820003753&payment_type=1&paymethod=directPay&return_url=http%3A%2F%2Fexample.com%2F%3Fs2member_pro_alipay_return%3D1&seller_email=zling%40example.com&service=create_direct_pay_by_user&show_url=http%3A%2F%2Fexample.com%2F&subject=example.com&total_fee=550&sign=0f0b6a44834ed2838ee0e98d91a2928f&sign_type=MD5
Basically, the variables aren't even included

In the second approach, all the variable turned into their literal value:
Code: Select all
https://www.alipay.com/cooperate/gateway.do?_input_charset=utf-8&body=托管套餐B&extra_common_param=example.com%7C%24name%7C%24email%7C%24domain%7C%24package%7C%24pay%7C%24oid%7C%24lang&notify_url=http%3A%2F%2Fexample.com%2F&out_trade_no=4f201e75977fa%7E1%3A%3A1+Y%7E1%7E120.32.3.116&partner=2088501820003753&payment_type=1&paymethod=directPay&return_url=http%3A%2F%2Fexample.com%2F%3Fs2member_pro_alipay_return%3D1&seller_email=zling%40example.com&service=create_direct_pay_by_user&show_url=http%3A%2F%2Fexample.com%2F&subject=example.com&total_fee=700&sign=1bcf9786e7ab10434384fd021a160651&sign_type=MD5
User avatar
angelazou
Registered User
Registered User
 
Posts: 72
Joined: July 14, 2011

Re: Variables Not Interpreted Correctly in Custom Value

Postby Raam Dev » January 26th, 2012, 12:45 pm

Code: Select all
$button = do_shortcode('[s2Member-PayPal-Button level="1" ccaps="" desc="Shared Plan B" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="example.com|$fn|$email|$domain|$package|$pay|$oid|$lang" ta="0" tp="0" tt="D" ra="87.45" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]'); 


In the above code example, $email will not be treated as a variable by PHP because it's enclosed within the single quotes of the do_shortcode() function.

For example,

Code: Select all
$first = "Raam"
$last = "Dev"
echo "Hello $first $last"; // outputs Hello Raam Dev
echo 'Hello $first $last'; // outputs Hello $first $last
echo 'Hello first name ' . $first . ' and last name ' . $last . '!'; // outputs Hello first name Raam and last name Dev!
 


For PHP to treat $first as a variable, it must exist between double-quotes, not single-quotes (or it must exist outside of the quotes). Please see PHP Variable Basics for more info.

In your do_shortcode() function, you can close and open your single quotes to have PHP translate the variables that need to be translated:

Code: Select all
$button = do_shortcode('[s2Member-PayPal-Button level="1" ccaps="" desc="Shared Plan B" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="example.com|' . $fn . '|' . $email . '|' . $domain . '|' . $package . '|' . $pay . '|' . $oid . '|' . $lang . '" ta="0" tp="0" tt="D" ra="87.45" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]'); 
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron