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™

Custom Registration Fields ( developer/video )

Common Questions/Problems/Tips. Posted by Administrators & Support Reps.

Custom Registration Fields ( developer/video )

Postby Jason Caldwell » March 26th, 2011, 8:02 pm

Custom Registration Fields ( a developer how-to )

How to set option values dynamically,
and how to set a default selected option value too.


Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
Code: Select all
<?php
/*
Setting options dynamically for Custom Registration Fields.
*/
add_action ("ws_plugin__s2member_before_custom_field_gen", "my_dynamic_field_options");
function my_dynamic_field_options ($vars = array ())
    {
        $_field = &$vars["__refs"]["_field"]; /* By "reference". */
        /* See: http://www.php.net/manual/en/language.references.spot.php. */
        /**/
        if ($_field["id"] === "country_code")
            {
                $_field["options"] = "US|United States|default" . "\n";
                $_field["options"] .= "CA|Canada" . "\n";
                $_field["options"] .= "VI|Virgin Islands (U.S.)";
            }
    }
/*
Setting a default value for Custom Registration Fields.
*/
add_action ("ws_plugin__s2member_before_custom_field_gen", "my_dynamic_field_values");
function my_dynamic_field_values ($vars = array ())
    {
        $references = &$vars["__refs"]; /* Array of variable "references". */
        $_field = &$vars["__refs"]["_field"]; /* By "reference". */
        /* See: http://www.php.net/manual/en/language.references.spot.php. */
        /**/
        if ($_field["id"] === "country_code")
            {
                if (empty ($references["_submission"]) && empty ($references["_value"]))
                    /* If a form was not just submitted. And, there is no default value. */
                    
                    $references
["_value"] = "CA"; /* Set the default value. */
            }
    }
?>

Video
I'm also attaching a video tutorial on this topic,
where I explain how this code works in great detail.

MP4 Video file: http://www.s2member.com/wp-content/uplo ... ically.mp4
~ 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: Custom Registration Fields ( developer/video )

Postby YourOnlineGuy » June 20th, 2011, 10:44 pm

Hi There Jason,

I am having an issue with the Custom Reg. Fields now that I have upgraded my s2member.
I am not being able to edit my custom reg fields.

I have included a short 2min email video demonstrating the issue I am having ,
http://screencast.com/t/y26KK32sdb4

Thanks for you direction.

Jasper
User avatar
YourOnlineGuy
Registered User
Registered User
 
Posts: 4
Joined: January 11, 2011

Re: Custom Registration Fields ( developer/video )

Postby YourOnlineGuy » June 21st, 2011, 7:04 pm

Hi. one more note...

When I updated s2m (following the update guide from this forum), I did remove the
`/plugins/s2member-logs/` and `/plugins/s2member-files/`.

which I figured was ok since the guide read in step 3:
"3. Login via FTP, and delete the entire `/wp-content/plugins/s2member` directory.
You can leave `/plugins/s2member-logs/` and `/plugins/s2member-files/`."

Also, the warning I get when I preview my registration page (http://youronlineguy.com/members/wp-log ... n=register) reads:
Warning: Invalid argument supplied for foreach() in /home/gbpmxnig/public_html/youronlineguy.com/members/wp-content/plugins/s2member/includes/classes/custom-reg-fields.inc.php on line 293


I have viewed the contents of the .php file referred to but really am not sure what I am looking for or how to fix this.

Let me know if you need me to send you a copy of the /custom-reg-feilds.inc.php

Thanks again.
User avatar
YourOnlineGuy
Registered User
Registered User
 
Posts: 4
Joined: January 11, 2011

Re: Custom Registration Fields ( developer/video )

Postby Jason Caldwell » June 22nd, 2011, 3:12 am

Thanks for reporting this important issue.
It sounds like you might have updated from a much older version of s2Member. There is a known issue with Custom Field configuration being lost when upgrading from s2Member v3.2.6 ( or lower ) up to s2Member 110604+. In order to correct this conflict, you will need to first upgrade to s2Member v3.2.7, save your General Options for s2Member, and then upgrade again to the latest release.

You can get a copy of s2Member v3.2.7 here:
http://wordpress.org/extend/plugins/s2member/download/


OR, you can just add these lines of code to the latest release of s2Member,
inside /s2member/includes/syscon.inc.php, at line #287.
Code: Select all
/*
Backward compatibility for "custom_reg_fields", which was re-formatted in v3.2.7 to a JSON encoded array of fields.
*/
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"] && !$options["custom_reg_fields"] && !is_array (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])))
    {
        $fields = array (); /* Initialize the new array of field objects. */
        /**/
        foreach (preg_split ("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) as $field)
            {
                $required = (preg_match ("/\*/", $field)) ? 'yes' : 'no';
                $editable = (preg_match ("/\^/", $field)) ? 'no' : 'yes';
                /**/
                if ($field = trim ($field, "^* \t\n\r\0\x0B"))
                    {
                        $fields[] = array ("id" => $field, "label" => $field, "type" => "text", "options" => "", "expected_format" => "", "required" => $required, "levels" => "all", "editable" => $editable, "classes" => "", "styles" => "", "attrs" => "");
                    }
            }
        /**/
        $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"] = json_encode ($fields);
        /**/
        unset ($une, $editable, $req, $required, $field, $fields);
    } 
~ 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: Custom Registration Fields ( developer/video )

Postby YourOnlineGuy » June 22nd, 2011, 10:39 am

Hi Jason...
Thank you for you assistance!
Please see this brief video, responding to your reply:
http://screencast.com/t/GMgs53b8xw

Jasper Welsh

--------------
Summary:
I re-upgraded via your v3.2.7 link and no change to my issue.

I then attempted to revise the syscon.inc.php file
My result generated this following message when trying to access my url:
Warning: Cannot modify header information - headers already sent by (output started at /home/gbpmxnig/public_html/youronlineguy.com/members/wp-content/plugins/s2member/includes/syscon.inc.php:1) in /home/gbpmxnig/public_html/youronlineguy.com/members/wp-includes/pluggable.php on line 897

Note: I am not familiar with code and would appreciate you assistance implementing this line of code.

Thanks again!
User avatar
YourOnlineGuy
Registered User
Registered User
 
Posts: 4
Joined: January 11, 2011

Re: Custom Registration Fields ( developer/video )

Postby Jason Caldwell » June 25th, 2011, 12:34 am

Thanks for reporting back.
I'm attaching a patched copy of syscon.inc.php for you.
syscon.inc.zip
(6.61 KiB) Downloaded 111 times

* Please use this file with s2Member v110620.
~ 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: Custom Registration Fields ( developer/video )

Postby YourOnlineGuy » June 25th, 2011, 12:18 pm

Jason...

Thank you! Since I was still in the setup process, I also backedup my wordpress install and uninstalled/reinstalled wordpress...

Everything is working as it should be now.

I really appreciate all your assistance!
User avatar
YourOnlineGuy
Registered User
Registered User
 
Posts: 4
Joined: January 11, 2011

Re: Custom Registration Fields ( developer/video )

Postby fgamimarlik » August 29th, 2011, 2:04 am

Hello,

I installed the latest version but i couldn't add any extra field in "Customer Registration Fields". I would be very pleased if you can help me to solve this problem

br
gürdal
Attachments
custom.JPG
User avatar
fgamimarlik
Registered User
Registered User
 
Posts: 9
Joined: August 29, 2011

Re: Custom Registration Fields ( developer/video )

Postby fgamimarlik » August 29th, 2011, 4:18 am

Also there is a error icon in login are.
When i click i get this message

___________________________

Kullanıcı Aracısı: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; Tablet PC 2.0; Zune 4.7)
Tarih damgası: Mon, 29 Aug 2011 09:18:02 UTC


İleti: Sözdizimi hatası
Satır: 1
Karakter: 1
Kod: 0
URI: http://www.fga.com.tr/?ws_plugin__s2mem ... 3378591960
User avatar
fgamimarlik
Registered User
Registered User
 
Posts: 9
Joined: August 29, 2011

Re: Custom Registration Fields ( developer/video )

Postby Cristián Lávaque » August 29th, 2011, 7:14 pm

You may have a JavaScript error, which could explain the problem in the Custom Registartion Fields panel.

Let me know if this video helps find it: http://www.s2member.com/options-page-di ... ing-video/
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Registration Fields ( developer/video )

Postby fgamimarlik » September 2nd, 2011, 6:13 am

Dear Cristián,
First thank you very much for your answer.

I try to find the error. this is the only error message that i get.

After that i unactivated all plugins. uninstall and re install smember but nothings change.

i open the plugin folder with ftp browser. i put "-" prefix for all plugins. than uninstall and re install smember but nothings change.

I would be very pleased if i can hear some suggestions from you

br
gürdal
Attachments
error1.JPG
User avatar
fgamimarlik
Registered User
Registered User
 
Posts: 9
Joined: August 29, 2011

Re: Custom Registration Fields ( developer/video )

Postby fgamimarlik » September 2nd, 2011, 3:24 pm

i reinstall everthing and fix the problem

thanks
User avatar
fgamimarlik
Registered User
Registered User
 
Posts: 9
Joined: August 29, 2011

Re: Custom Registration Fields ( developer/video )

Postby Cristián Lávaque » September 2nd, 2011, 11:38 pm

I'm glad you fixed it! Thanks for the update. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom Registration Fields ( developer/video )

Postby wibbsy » December 6th, 2011, 4:44 am

Hi guys

I have a question about being able to write to the custom profile fields after registration.

I am aware that is S2 member you can write/add custom capabilities after registration. But unaware of how to write to the profile fields.

My requirement is that I have a users on my wp site. One of the pages that requires level0 access, there is an call to an external database (done via PHP) to provide some data. My PHP sends some of the user profile fields in the PHP request packet and logs on the external database the WP username of the request...This all works fine.

What I want to do it put an IF loop in the PHP that essentially says:
Has this member already made a request to this database at some point in the past?
Yes > Don't execute DB request > return an error ("Data was already provided on 01/11/11"); or
No > Execute DB request > return data > Update profile field 'request' to true.


It's the updating of the request filed that I'm struggling with. I can't put the field at registration as the user doesn't know at that stage whether or not they will be making the DB request and also I would like to make the field invisible (and user uneditable) so they don't even know it's there.

To me this seems simple in logic but struggling to be able to find the option to write or create a new user profile field 'on-the'fly'.

Could this be done using custom capability?
User avatar
wibbsy
Registered User
Registered User
 
Posts: 10
Joined: November 2, 2011

Re: Custom Registration Fields ( developer/video )

Postby wibbsy » December 6th, 2011, 6:45 am

I've tried to implement this as custom capability and my code works fine for adding user details to my database. However no matter what i do the parent IF statement always returns 1/true? I've tried under may different conditions with many different variations and nothing seems to change this?

Code: Select all


$user 
wp_get_current_user();
$current_user json_decode(S2MEMBER_CURRENT_USER_FIELDStrue);

//test to see if they already have the custom capability 'request'
if(current_user_can("access_s2member_ccap_request")){

 echo 
"You already have added your details to the database";

}

//if not then run the database request

else 
{
$prepost['action'] = "addUser";
$prepost['email'] = $current_user['email'];
$prepost['forename'] = $current_user['first_name'];
$prepost['surname'] = $current_user['last_name'];
$prepost['company'] = $current_user['type_name'];
$prepost['type'] = $current_user['user_type'];
$prepost['title'] = $current_user['role'];
$prepost['phone'] = $current_user['phone'];
$prepost['dob'] = $current_user['dob'];
$prepost['add1'] = $current_user['address1'];
$prepost['add2'] = $current_user['address2'];
$prepost['town'] = $current_user['city'];
$prepost['county'] = $current_user['state'];
$prepost['country'] = $current_user['country'];
$prepost['postCode'] = $current_user['zip'];

//traverse array and prepare data for posting (key1=value1)
foreach ( $prepost as $key => $value
{
    
$post_items[] = $key '=' $value;
}

//create the final string to be posted using implode()
//print_r($prepost);
$post_string implode ('&'$post_items);
//create cURL connection
//echo $post_string;

$curl_connection =
curl_init('http://**removed**');
//set options

curl_setopt($curl_connectionCURLOPT_CONNECTTIMEOUT30);
curl_setopt($curl_connectionCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connectionCURLOPT_RETURNTRANSFERtrue);
curl_setopt($curl_connectionCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($curl_connectionCURLOPT_FOLLOWLOCATION1);
//set data to be posted

curl_setopt($curl_connectionCURLOPT_POSTFIELDS$post_string);
//perform our request

$result curl_exec($curl_connection);
//show information regarding the request

$splitResult explode('-'$result);

//The status is whether it worked or it didnt, can be 'False' or 'True'
$status $splitResult[0];
//The message is what to display to the user
$message =  $splitResult[1];

if(
$status == 'True')
{
//If everything went well
echo $message;
echo 
"
Please check your email for your user details!
"
;

}
else
{
//something went wrong - tell the user
echo $message;


}
//print_r(curl_getinfo($curl_connection));

//close the connection
curl_close($curl_connection);

//now that they have added details to database, add custom capability 'request' so they are unable to run the script again

$user->add_cap("access_s2member_ccap_request");

Last edited by Cristián Lávaque on December 18th, 2011, 4:44 pm, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
wibbsy
Registered User
Registered User
 
Posts: 10
Joined: November 2, 2011

Re: Custom Registration Fields ( developer/video )

Postby gavindegraw1 » December 16th, 2011, 3:49 am

I guess your code look like decent & correct, you can use it anywhere you want !
User avatar
gavindegraw1
Registered User
Registered User
 
Posts: 1
Joined: November 28, 2011

Re: Custom Registration Fields ( developer/video )

Postby Cristián Lávaque » December 19th, 2011, 4:30 am

wibbsy wrote:It's the updating of the request filed that I'm struggling with. I can't put the field at registration as the user doesn't know at that stage whether or not they will be making the DB request and also I would like to make the field invisible (and user uneditable) so they don't even know it's there.


You can create a custom profile field that has the Allow Profile Edits setting set to "Yes (editable after registration / invisible during registration)".

I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to Common Questions/Problems/Tips

Who is online

Users browsing this forum: No registered users and 1 guest

cron