Hello,
I’d like to add a custom user field to dynamically create a unique 32 character user ID when a user registers with s2member.
I created a custom profile field ID called “apikey”. Then I added this code to s2-hacks.php.
Unfortunately, no unique ID is being generated when registering a new user.
Maybe, the code example provided from Jason is not working for my purpose.
The PHP code works without drouble – see http://lernpress.de/apikey.php
<?php
echo md5(uniqid(mt_rand(), true));
?>
Would be great if you guys can help me out.
Thanks
http://www.primothemes.com/forums/viewtopic.php?f=4&t=2822
http://www.s2member.com/codex/stable/source/s2member/includes/classes/custom-reg-fields.inc.php/
http://blog.vivekv.com/uniqid-the-easiest-way-to-generate-unique-strings.html
<?php
/* ### Setting options dynamically for Custom Registration Fields. ### */
add_action ("ws_plugin__s2member_before_custom_field_gen", "apikey_field_options");
function apikey_field_options ($vars = array ())
{
$_field = &$vars["__refs"]["_field"]; /* By "reference". */
/* See: http://www.php.net/manual/en/language.references.spot.php. */
/**/
if ($_field["id"] === "apikey")
{
$_field["options"] = md5(uniqid(mt_rand(), true));
}
}
/*
Setting a default value for Custom Registration Fields.
*/
add_action ("ws_plugin__s2member_before_custom_field_gen", "apikey_field_values");
function apikey_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"] === "apikey")
{
if (empty ($references["_submission"]) && empty ($references["_value"]))
/* If a form was not just submitted. And, there is no default value. */
$references["_value"] = md5(uniqid(mt_rand(), true)); /* Set the default value. */
}
}
?>