I’ve noticed many threads on this site that have the same problems i’m trying to fix (not necessarily these listed below, but others) with conversation from s2member support on how to “test for bugs”, but there are never any solutions added at the end. Just “thread closed”. bummer.
;) so, I’m going to update with my successful fixes for others that might run into the same issues.
ISSUE1
resolved by moving the custom template paypal-return.php from the child theme directory to the main template directory.
ISSUE2
The caching issue was resolved by…
1 – added wp_capabilities to the non cached database queries as a fix to keep the site from caching the users level. just a note on caching *get_user_meta queries catch no matter what, use manual queries to avoid catch if in the non cached list.
2 – added s2member_paypal_return and membership to “Never cache the following pages:” on Database cache.
3 – added membership and membership/ to “Never cache the following pages:” on Page Cache.
4 – added code to the themes/childtheme/header.php to recognize if on the s2member_paypal_return url, then add ?ver=1234 (1234 being the pjp time() stamp for a completely new number) at the end of all links including the menu bar. This caused the site to recheck the users level and everything seemed fine after this.
ISSUE3
s2hacks.php MUST GO in a /wp-content/mu-plugins/ directory – even if you have to make it.
There was a typo on the wp-mail that was causing the custom email to the member to not work. $user_message should have been $users_message. Also NOTE: adding the print all $vars caused Google to flag the site email as spam, so many of the missing emails to the paypal user and the custom site notification email were later found in spam. new s2hacks.php file included below…
<?php
/*
s2member hacks for mysite.com
more info about the mu-plugins directory http://codex.wordpress.org/Must_Use_Plugins
Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
per: http://www.primothemes.com/forums/viewtopic.php?f=4&t=10368#p33365 and http://www.s2member.com/kb/hacking-s2member/
# Optional. s2Member® passes you an array of defined variables.
# print_r($vars); # Would give you a list of defined variables.
# These are PHP variables defined within the scope of the Hook,
# at the precise point in which the Hook is fired by s2Member®.
# $vars["__refs"] are also included (with some Hooks).
# These are internal PHP variable references (very useful).
# To learn all about references, please see PHP documentation:
# http://www.php.net/manual/en/language.references.pass.php
*/
//Include WordPress
include('/home/content/41/9502741/html/mysite/wp-config.php');
define('WP_USE_THEMES', false);
//require('/home/content/41/9502741/html/mysite/wp-blog-header.php'); <--caused a fatal error
include('/home/content/41/9502741/html/mysite/wp-contents/plugins/mysite/mysite.php');
global $local_wp_load; //require_once('/home/content/41/9502741/html/mysite/wp-load.php');
//customize the member upgrade/downgrade email since our members are aready free members when they pay for membership.
/*
//http://www.s2member.com/codex/stable/source/s2member/includes/classes/paypal-notify-in-subscr-modify-w-level.inc.php/
//paypal_notify_in_subscr_modify_w_level.inc.php
c_ws_plugin__s2member_email_configs::email_config () . wp_mail ($paypal["payer_email"], apply_filters ("ws_plugin__s2member_modification_email_sbj", _x ("Thank you! Your account has been updated.", "s2member-front", "s2member"), get_defined_vars ()), apply_filters ("ws_plugin__s2member_modification_email_msg", _x ("Thank you! You've been updated to:", "s2member-front", "s2member") . "\n" . $paypal["item_name"] . "\n\n" . _x ("Please log back in now.", "s2member-front", "s2member") . "\n" . wp_login_url (), get_defined_vars ()), "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") . c_ws_plugin__s2member_email_configs::email_config_release ();
//paypal_notify_in_subscr_or_wa_w_level.inc.php
c_ws_plugin__s2member_email_configs::email_config () . wp_mail ($paypal["payer_email"], apply_filters ("ws_plugin__s2member_modification_email_sbj", _x ("Thank you! Your account has been updated.", "s2member-front", "s2member"), get_defined_vars ()), apply_filters ("ws_plugin__s2member_modification_email_msg", _x ("Thank you! You've been updated to:", "s2member-front", "s2member") . "\n" . $paypal["item_name"] . "\n\n" . _x ("Please log back in now.", "s2member-front", "s2member") . "\n" . wp_login_url (), get_defined_vars ()), "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") . c_ws_plugin__s2member_email_configs::email_config_release ();
*/
add_filter( "ws_plugin__s2member_modification_email_sbj", "my_s2_modification_sbj", 10, 2 );
function my_s2_modification_sbj( $s2member_default_sbj, $vars = array() ){
if( isset($vars["user_id"]) ){
$wp_userdata = get_userdata($vars["user_id"]);
$users_name = $wp_userdata->display_name;
//the email subject:
return $users_name." is ready for mysite!";
} else {
//the email subject:
return "Your mysite Membership is ready!";
}
}//end function my_s2_modification_sbj( $s2member_default_sbj, $vars = array() )
add_filter( "ws_plugin__s2member_modification_email_msg", "my_s2_modification_msg", 10, 2 );
function my_s2_modification_msg( $s2member_default_msg, $vars = array() ){
global $homepage_url;
//the email message:
//before hacks... return "Thank you! You've been updated to:\n" . $vars["paypal"]["item_name"] . "\n\nPlease log back in now:\n" . wp_login_url ();
//set the members email and the site notification to send html
$headers = 'From: mysite <info@mysite.com>' . "\r\n" .
//'Reply-To: ' . $from. "\r\n" .
'Content-Type: text/html'; //<-- adding html email ability
$wp_userdata = get_userdata($vars["user_id"]);
$usersid = $vars["user_id"];
$users_email = $wp_userdata->user_email;
$users_name = $wp_userdata->display_name;
$sub_id = $vars["paypal"]["subscr_id"];
$item_name = $vars["paypal"]["item_name"];
//Build the user a message
$users_subject = $users_name."! Your mysite membership is complete";
$users_message = '<span style="font-family: Verdana, Geneva, sans-serif;">';
$users_message .= 'Thanks '.$users_name.'! Your mysite membership is complete.<br>';
$users_message .= '<br>';
$users_message .= 'Remember to sign in the first time with the same social network, so mysite will know who you are. Associate your other networks on your profile after your first sign in.<br>';
$users_message .= '<br>';
$users_message .= '<h4><a href="'.$homepage_url.'/help/?id='.$usersid.'">Go fill out your profile and reply to some posts!</a></h4><br>';
$users_message .= '<a href="'.$homepage_url.'/help/?id='.$usersid.'"><img src="http://mysite.com/wp-contents/themes/mysite/images/mysite_image.gif" border="0px"></a>';
$users_message .= 'This link will help you get started: '.$homepage_url.'/help/?id='.$usersid.'<br>';
$users_message .= '<br>';
$users_message .= '<br>';
$users_message .= '<b>mysite Member Info</b><br>';
$users_message .= 'Name: '.$users_name.'<br>';
$users_message .= 'mysite ID: '.$usersid.'<br>';
$users_message .= 'email: '.$users_email.'<br>';
$users_message .= 'Payment Subscription ID: '.$sub_id.' '.$item_name.'<br>';
$users_message .= '<br>';
$users_message .= 'If you have any trouble, please feel free to reply or forward this email to support@mysite.com for help.';
$users_message .= '</span>';
// SEND the mysite Member an email...
$member_email = wp_mail($users_email, $users_subject, $users_message, $headers);
if( $member_email === true ){ $member_email = 'Sent Successfully'; }else{ $member_email = 'Failed'; }
//build mysite a notification
//$print_vars = print_r($vars, TRUE);
$mysite_subject = 'New mysite Member: '.$users_name;
$mysite_message = "Member Name: ".$users_name."<br>";
$mysite_message .= "mysite ID: ".$usersid."<br>";
$mysite_message .= "Users Email: ".$users_email."<br>";
$mysite_message .= "<br>";
$mysite_message .= "Payment Subscription ID: ".$sub_id."<br>";
$mysite_message .= "Item: ".$item_name."<br>";
$mysite_message .= "PayPal Email: ".$vars["paypal"]["payer_email"]."<br>";
$mysite_message .= "<br>";
//$mysite_message .= "All $vars: ".$print_vars; <-- causes gmail spam
$mysite_message .= "Member Email: ".$member_email;
// Send email to mysite - assumes $to, $subject, $message have already been defined earlier...
wp_mail("members@mysite.com", $mysite_subject, $mysite_message, $headers);
//Send the Paypal user an email...
//before hacks... return "Thank you! You've been updated to:\n" . $vars["paypal"]["item_name"] . "\n\nPlease log back in now:\n" . wp_login_url ();
/*NOTE these lines were tried and did not send an email at all as return:
//triggers SPAM filter "Testing all $vars: ".$print_vars;
$paypal_users_message (with each line as $paypal_users_message .= "all quotes "and no apostrophies" as noted above"
*/
/**the following return results in a successful email to the paypay email**
**************************************************************************
Thanks Mira Concepts! Your mysite membership is complete.
Go fill out your profile and reply to some posts!
http://mysite.com/profile/
Remember to sign in the first time with the same social network, so mysite will know who you are. Associate your other networks on your profile after your first sign in.
mysite Member's Info...
Name: Mira Concepts
ID: 82
email: *************@gmail.com
Payment Subscription# ************* mysite.com $2 yearly (recurring for ongoing access).
If you have any trouble, please feel free to reply to this email for help.
support@mysite.com
*/
if( $users_email == $vars["payer_email"] ){
return "Thanks ".$users_name."! Your mysite membership is complete.\n\nGo fill out your profile and reply to some posts! Marco?!\nThis link will help you get started: ".$homepage_url."/help/?id=".$usersid."\n\nRemember to sign in the first time with the same social network, so mysite will know who you are. Associate your other networks on your profile after your first sign in.\n\n\nmysite Member's Info...\nName: ".$users_name."\nmysite ID: ".$usersid."\nemail: ".$users_email."\n\nPayment Subscription ID: ".$sub_id." ".$item_name."\n\nIf you have any trouble, please feel free to reply or forward this email to support@mysite.com for help.";
}
}//ENd function my_s2_modification_msg( $s2member_default_msg, $vars = array() )
/***********************All the $vars.............................................................
$vars: Array
[invoice] => 508450cc762d1~*************
[amount1] => 0.00
[amount3] => 2.00
[subscr_date] => 12:45:51 Oct 21, 2012 PDT
[payer_id] => *************
[mc_amount1] => 0.00
[mc_amount3] => 2.00
[charset] => windows-1252
[first_name] => *************
[option_selection1] => 74
[option_selection2] => *************
[reattempt] => 1
[notify_version] => 3.7
[subscr_id] => *************
[custom] => mysite.com
[payer_status] => verified
[business] => info@myste.net
[verify_sign] => *************
[payer_email] => order@mysite.com
[option_name1] => Referencing Customer ID
[option_name2] => Customer IP Address
[payer_business_name] => *************
[last_name] => *************
[receiver_email] => info@mysite.net
[recurring] => 1
[txn_type] => subscr_signup
[item_name] => mysite.com FREE for 6 months, then $2 yearly (recurring for ongoing access).
[mc_currency] => USD
[item_number] => 1
[residence_country] => US
[period1] => 6 M
[period3] => 1 Y
[ipn_track_id] => *************
[s2member_log] => Array
(
[0] => IPN received on: Sun Oct 21, 2012 7:46:13 pm UTC
[1] => s2Member POST vars verified through a POST back to PayPal®.
[2] => s2Member originating domain ( `$_SERVER["HTTP_HOST"]` ) validated.
)
[subscr_gateway] => paypal
)
[_paypal] => Array
(
[invoice] => *************
[amount1] => 0.00
[amount3] => 2.00
[subscr_date] => 12:45:51 Oct 21, 2012 PDT
[payer_id] => *************
[mc_amount1] => 0.00
[mc_amount3] => 2.00
[charset] => windows-1252
[first_name] => *************
[option_selection1] => 74
[option_selection2] => *************
[reattempt] => 1
[notify_version] => 3.7
[subscr_id] => *************
[custom] => mysite.com
[payer_status] => verified
[business] => info@*************.net
[verify_sign] => *************
[payer_email] => order@*************.com
[option_name1] => Referencing Customer ID
[option_name2] => Customer IP Address
[payer_business_name] => *************
[last_name] => *************
[receiver_email] => info@*************.net
[recurring] => 1
[txn_type] => subscr_signup
[item_name] => mysite.com FREE for 6 months, then $2 yearly (recurring for ongoing access).
[mc_currency] => USD
[item_number] => 1
[residence_country] => US
[period1] => 6 M
[period3] => 1 Y
[ipn_track_id] => *************
)
[_paypal_s] => a:33:{s:7:"invoice";s:27:"*************1~*************";s:7:"amount1";s:4:"0.00";s:7:"amount3";s:4:"2.00";s:11:"subscr_date";s:25:"12:45:51 Oct 21, 2012 PDT";s:8:"payer_id";s:13:"*************";s:10:"mc_amount1";s:4:"0.00";s:10:"mc_amount3";s:4:"2.00";s:7:"charset";s:12:"windows-1252";s:10:"first_name";s:5:"*********";s:17:"option_selection1";s:2:"74";s:17:"option_selection2";s:13:"*************";s:9:"reattempt";s:1:"1";s:14:"notify_version";s:3:"3.7";s:9:"subscr_id";s:14:"*************";s:6:"custom";s:13:"mysite.com";s:12:"payer_status";s:8:"verified";s:8:"business";s:21:"info@*********.net";s:11:"verify_sign";s:56:"*************-*************.*************";s:11:"payer_email";s:24:"order@*************.com";s:12:"option_name1";s:23:"Referencing Customer ID";s:12:"option_name2";s:19:"Customer IP Address";s:19:"payer_business_name";s:36:"************* Art and Design Studio";s:9:"last_name";s:9:"*************";s:14:"receiver_email";s:21:"info@*********.net";s:9:"recurring";s:1:"1";s:8:"txn_type";s:13:"subscr_signup";s:9:"item_name";s:79:"mysite.com FREE for 6 months, then $2 yearly (recurring for ongoing access).";s:11:"mc_currency";s:3:"USD";s:11:"item_number";s:1:"1";s:17:"residence_country";s:2:"US";s:7:"period1";s:3:"6 M";s:7:"period3";s:3:"1 Y";s:12:"ipn_track_id";s:13:"*************";}
[invoice] => 508450cc762d1~*************
[amount1] => 0.00
[amount3] => 2.00
[subscr_date] => 12:45:51 Oct 21, 2012 PDT
[payer_id] => *************
[mc_amount1] => 0.00
[mc_amount3] => 2.00
[charset] => windows-1252
[first_name] => *********
[option_selection1] => 74
[option_selection2] => *************
[reattempt] => 1
[notify_version] => 3.7
[subscr_id] => *************
[custom] => mysite.com
[payer_status] => verified
[business] => info@*********.net
[verify_sign] => *************
[payer_email] => order@*************.com
[option_name1] => Referencing Customer ID
[option_name2] => Customer IP Address
[payer_business_name] => ************* Art and Design Studio
[last_name] => *********
[receiver_email] => info@*********.net
[recurring] => 2.00
[txn_type] => subscr_signup
[item_name] => mysite.com FREE for 6 months, then $2 yearly (recurring for ongoing access).
[mc_currency] => USD
[item_number] => 1
[residence_country] => US
[period1] => 6 M
[period3] => 1 Y
[ipn_track_id] => *************
[s2member_log] => Array
(
[0] => IPN received on: Sun Oct 21, 2012 7:46:13 pm UTC
[1] => s2Member POST vars verified through a POST back to PayPal®.
[2] => s2Member originating domain ( `$_SERVER["HTTP_HOST"]` ) validated.
[3] => s2Member `txn_type` identified as ( `web_accept|subscr_signup` ).
[4] => s2Member `txn_type` identified as ( `web_accept|subscr_signup` ) w/ update vars.
[5] => s2Member Level/Capabilities updated w/ advanced update routines.
)
[subscr_gateway] => paypal
[eotper] =>
[ccaps] =>
[level] => 1
[ip] => *************
[initial_term] => 6 M
[initial] => 0.00
[regular] => 2.00
[regular_term] => 1 Y
)
*/
?>
—
yea, now on to more issues with google checkout. OH BOY lol. This plugin is very helpful and we purchased the multi-site license. I would not however recommend it for those who don’t have time to put into debugging and writing custom code for customizing it to work with their site. The basic setup alone takes a person willing to do a lot of reading.
It would be a great feature to add a member level upgrade custom email, so the s2hacks file wouldn’t needed. Also, sending that email to both the paypal user and the site member if their emails differ.
cheers, and again thanks for the tips :)