// Add wallet fields to Ultimate Member registration form
add_filter('um_fields', function($fields) {
$wallet_types = [
'btc' => 'Bitcoin (BTC) Wallet Address',
'eth' => 'Ethereum (ETH) Wallet Address',
'usdt_trc20' => 'USDT (TRC20) Wallet Address',
'usdt_erc20' => 'USDT (ERC20) Wallet Address',
'usdt_bep20' => 'USDT (BEP20) Wallet Address',
'bnb' => 'BNB Wallet Address',
];
// Debug: Log when the filter is called
error_log('um_fields filter called. Current fields: ' . print_r(array_keys($fields), true));
foreach ($wallet_types as $key => $label) {
$field_key = 'wallet_' . $key;
// Only add the field if it doesn't already exist to avoid duplicates
if (!isset($fields[$field_key])) {
$fields[$field_key] = array(
'title' => $label,
'metakey' => $field_key,
'type' => 'text',
'label' => $label,
'required' => 0, // Not required during registration
'public' => 1, // Visible to user
'editable' => 1, // Editable by user
'show_in_register_form' => true, // Ensure it shows in registration form
'account_only' => false, // Allow in registration form, not just account page
'in_register' => true, // Explicitly allow in registration form
'in_profile' => true, // Also allow in profile form
);
error_log("Added field $field_key to um_fields");
}
}
// Debug: Log the updated fields
error_log('um_fields filter updated fields: ' . print_r(array_keys($fields), true));
return $fields;
}, 9999, 1); // Higher priority to ensure it runs after other filters
// Ensure wallet fields are added to the registration form by assigning them to the form
add_action('um_after_form_fields', function($args) {
// Get the form ID
$form_id = isset($args['form_id']) ? $args['form_id'] : 0;
error_log("um_after_form_fields called for form ID: $form_id");
// Only apply to the registration form (adjust form ID if needed)
// Default Ultimate Member registration form ID is often 1, but check in UM > Forms
if ($form_id != 1) { // Replace 1 with your registration form ID if different
return;
}
$wallet_types = [
'btc' => 'Bitcoin (BTC) Wallet Address',
'eth' => 'Ethereum (ETH) Wallet Address',
'usdt_trc20' => 'USDT (TRC20) Wallet Address',
'usdt_erc20' => 'USDT (ERC20) Wallet Address',
'usdt_bep20' => 'USDT (BEP20) Wallet Address',
'bnb' => 'BNB Wallet Address',
];
foreach ($wallet_types as $key => $label) {
$field_key = 'wallet_' . $key;
// Check if the field exists in the form
if (!isset($args['fields']) || !in_array($field_key, array_column((array)$args['fields'], 'metakey'))) {
// Add the field to the form
$args['fields'][] = array(
'metakey' => $field_key,
'type' => 'text',
'label' => $label,
'required' => 0,
'public' => 1,
'editable' => 1,
);
error_log("Manually added field $field_key to form ID $form_id");
}
}
});
// Save wallet fields to user_wallets meta on registration
add_action('um_user_register', function($user_id, $args) {
$wallet_types = [
'btc' => 'Bitcoin (BTC) Wallet Address',
'eth' => 'Ethereum (ETH) Wallet Address',
'usdt_trc20' => 'USDT (TRC20) Wallet Address',
'usdt_erc20' => 'USDT (ERC20) Wallet Address',
'usdt_bep20' => 'USDT (BEP20) Wallet Address',
'bnb' => 'BNB Wallet Address',
];
$wallets = get_user_meta($user_id, 'user_wallets', true) ?: [];
foreach ($wallet_types as $key => $label) {
$field_key = 'wallet_' . $key;
if (isset($_POST[$field_key]) && !empty($_POST[$field_key])) {
$wallets[$key] = sanitize_text_field($_POST[$field_key]);
}
}
if (!empty($wallets)) {
update_user_meta($user_id, 'user_wallets', $wallets);
error_log("Saved wallet addresses for user $user_id: " . print_r($wallets, true));
}
}, 10, 2);
// Add wallet fields to Ultimate Member registration form
add_filter('um_fields', function($fields) {
$wallet_types = [
'btc' => 'Bitcoin (BTC) Wallet Address',
'eth' => 'Ethereum (ETH) Wallet Address',
'usdt_trc20' => 'USDT (TRC20) Wallet Address',
'usdt_erc20' => 'USDT (ERC20) Wallet Address',
'usdt_bep20' => 'USDT (BEP20) Wallet Address',
'bnb' => 'BNB Wallet Address',
];
// Debug: Log when the filter is called
error_log('um_fields filter called. Current fields: ' . print_r(array_keys($fields), true));
foreach ($wallet_types as $key => $label) {
$field_key = 'wallet_' . $key;
// Only add the field if it doesn't already exist to avoid duplicates
if (!isset($fields[$field_key])) {
$fields[$field_key] = array(
'title' => $label,
'metakey' => $field_key,
'type' => 'text',
'label' => $label,
'required' => 0, // Not required during registration
'public' => 1, // Visible to user
'editable' => 1, // Editable by user
'show_in_register_form' => true, // Ensure it shows in registration form
'account_only' => false, // Allow in registration form, not just account page
'in_register' => true, // Explicitly allow in registration form
'in_profile' => true, // Also allow in profile form
);
error_log("Added field $field_key to um_fields");
}
}
// Debug: Log the updated fields
error_log('um_fields filter updated fields: ' . print_r(array_keys($fields), true));
return $fields;
}, 9999, 1); // Higher priority to ensure it runs after other filters
// Ensure wallet fields are added to the registration form by assigning them to the form
add_action('um_after_form_fields', function($args) {
// Get the form ID
$form_id = isset($args['form_id']) ? $args['form_id'] : 0;
error_log("um_after_form_fields called for form ID: $form_id");
// Only apply to the registration form (adjust form ID if needed)
// Default Ultimate Member registration form ID is often 1, but check in UM > Forms
if ($form_id != 1) { // Replace 1 with your registration form ID if different
return;
}
$wallet_types = [
'btc' => 'Bitcoin (BTC) Wallet Address',
'eth' => 'Ethereum (ETH) Wallet Address',
'usdt_trc20' => 'USDT (TRC20) Wallet Address',
'usdt_erc20' => 'USDT (ERC20) Wallet Address',
'usdt_bep20' => 'USDT (BEP20) Wallet Address',
'bnb' => 'BNB Wallet Address',
];
foreach ($wallet_types as $key => $label) {
$field_key = 'wallet_' . $key;
// Check if the field exists in the form
if (!isset($args['fields']) || !in_array($field_key, array_column((array)$args['fields'], 'metakey'))) {
// Add the field to the form
$args['fields'][] = array(
'metakey' => $field_key,
'type' => 'text',
'label' => $label,
'required' => 0,
'public' => 1,
'editable' => 1,
);
error_log("Manually added field $field_key to form ID $form_id");
}
}
});
// Save wallet fields to user_wallets meta on registration
add_action('um_user_register', function($user_id, $args) {
$wallet_types = [
'btc' => 'Bitcoin (BTC) Wallet Address',
'eth' => 'Ethereum (ETH) Wallet Address',
'usdt_trc20' => 'USDT (TRC20) Wallet Address',
'usdt_erc20' => 'USDT (ERC20) Wallet Address',
'usdt_bep20' => 'USDT (BEP20) Wallet Address',
'bnb' => 'BNB Wallet Address',
];
$wallets = get_user_meta($user_id, 'user_wallets', true) ?: [];
foreach ($wallet_types as $key => $label) {
$field_key = 'wallet_' . $key;
if (isset($_POST[$field_key]) && !empty($_POST[$field_key])) {
$wallets[$key] = sanitize_text_field($_POST[$field_key]);
}
}
if (!empty($wallets)) {
update_user_meta($user_id, 'user_wallets', $wallets);
error_log("Saved wallet addresses for user $user_id: " . print_r($wallets, true));
}
}, 10, 2);