How can I take a custom field out of a loop or set a custom value to a field
-
.
– [x] 1.3.88 ( latest )
– [ ] 2.0 ( beta )I have two fields which are
“username” => “Username”,
“license_keys” => “License Key”,the license_key field i want to add a randomized string using generateRandomString() my question is how can i take the license key field out of the loop, how can i build these fields manually, or how can i inject the random string into the license key field while its still in the loop? I can paypal a donation for the assistance. I tried using if statements with no luck.
Or maybe how can I query if the license key field is NULL and if it is and does returns TRUE generate a random string and set/save it to the license key field?
Thanks in advanced ive been going crazy over this
add_filter(‘um_account_content_hook_license’, ‘um_account_content_hook_license’);
function um_account_content_hook_license( $output ){
ob_start();
function generateRandomString($length = 15) {
$characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$charactersLength = strlen($characters);
$randomString = ”;
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength – 1)];
}
return $randomString;
}
$custom_fields = [
“username” => “Username”,
“license_keys” => “License Key”,
];$rand_str = generateRandomString();
//SQL DATA IMPORT COMPLETE
foreach ($custom_fields as $key => $value) {$fields[ $key ] = array(
‘title’ => $value,
‘metakey’ => $key,
‘type’ => ‘select’,
‘label’ => $value,
);global $ultimatemember; $id = um_user(‘ID’);
$field_value = get_user_meta(um_user(‘ID’), $key, true) ? : ”;
$html = ‘<div class=”um-field um-field-‘.$key.'” data-key=”‘.$key.'”>
<div class=”um-field-label”>
<label for=”‘.$key.'”>’.$value.'</label>
<div class=”um-clear”></div>
</div>
<div class=”um-field-area”>
<input class=”um-form-field valid ”
type=”text” name=”‘.$key.'”
id=”‘.$key.'” value=”‘.$field_value.'”
placeholder=””
data-validate=”” data-key=”‘.$key.'”>
</div>
</div>’;echo $html;
}$fields = apply_filters( ‘um_account_secure_fields’, $fields, $id );
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
- The topic ‘How can I take a custom field out of a loop or set a custom value to a field’ is closed to new replies.