*NOTE: You should only use this function if you have a legal copy of s2member pro. Much of this code was copied from the s2member files.
I created a quick little class that you can put in an mu-plugin to add some of this functionality. It’s not perfect but it seems to work for me when I use it this way. Again, I have not done extensive testing on this function.
Step 1 -> Create a directory / file in this location:
http://yourdomain.com/wp-content/mu-plugins/s2-hacks.php
Step 2 -> Add this code to that file (s2-hacks.php):
<?php
//Dave Welch - Custom Fields In Custom Template Class
class DW_custom_template {
public static function get_s2_custom_field($id,$level=0){
$_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST));
/*
Obtain a possible response and/or validation error.
*/
$response = c_ws_plugin__s2member_pro_paypal_responses::paypal_registration_response($attr);
/*
Empty post vars on successful response.
*/
$_p = ($response["response"] && !$response["error"]) ? array(): $_p;
$custom_field_array = json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true);
foreach($custom_field_array as $k => $v){
if($v['id'] == $id){
$id_key = $k;
break;
}
}
//print_r($custom_field_array);
$fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level($level, "registration");
$custom_fields = '';
$field = $custom_field_array[$id_key];
if(!empty($custom_field_array)){
if(isset($field['id']) && $field['id'] == $id){
if(in_array($field["id"], $fields_applicable))//Field is applicable to Level 0?
{
$field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
$field_id_class = preg_replace("/_/", "-", $field_var);
if(!empty($field["section"]) && $field["section"] === "yes") // Starts a new section?
$custom_fields .= '<div id="s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-divider-section" class="s2member-pro-paypal-form-div s2member-pro-paypal-registration-form-div s2member-pro-paypal-form-custom-reg-field-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').' s2member-pro-paypal-form-custom-reg-field-'.$field_id_class.'-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').' s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').'">'.((!empty($field["sectitle"])) ? $field["sectitle"] : '').'</div>';
$custom_fields .= '<div id="s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-div" class="s2member-pro-paypal-form-div s2member-pro-paypal-registration-form-div s2member-pro-paypal-form-custom-reg-field-'.$field_id_class.'-div s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-div">'."\n";
$custom_fields .= '<label for="s2member-pro-paypal-registration-custom-reg-field-'.esc_attr($field_id_class).'" id="s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-label" class="s2member-pro-paypal-form-custom-reg-field-'.$field_id_class.'-label s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-label">'."\n";
$custom_fields .= '<span'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? ' style="display:none;"' : '').'>'.$field["label"].(($field["required"] === "yes") ? ' *' : '').'</span></label>'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? '' : '<br />')."\n";
$custom_fields .= c_ws_plugin__s2member_custom_reg_fields::custom_field_gen(__FUNCTION__, $field, "s2member_pro_paypal_registration[custom_fields][", "s2member-pro-paypal-registration-custom-reg-field-", "s2member-pro-paypal-custom-reg-field-".$field_id_class." s2member-pro-paypal-registration-custom-reg-field-".$field_id_class, "", ($tabindex = $tabindex + 1), "", $_p, $_p["s2member_pro_paypal_registration"]["custom_fields"][$field_var], "registration");
$custom_fields .= '</div>'."\n";
return $custom_fields;
}
else {
return 'Not Applicable Field';
}
}
else {
return 'Invalid ID';
}
}
else {
return 'No Custom Fields';
}
}
}
?>
Step 3 -> Place this line of code in your template where you want your custom field to be. You will use the Unique ID for that field to call it.
<?php echo DW_custom_template::get_s2_custom_field('your-field-id-here'); ?>
If you have any questions, let me know. If it doesn’t work let me know too.. again this has been tested very little. lol
Hope it helps,
Dave