Drei Hooks kommen zur Anwendung:
add_action('register_form','show_country_field');
add_action('register_post','check_country_field',10,3);
add_action('user_register', 'register_country_field');
Die Funktionen
function wle_show_country_field() {
$user_country = ( isset( $_POST['user_country'] ) ) ? $_POST['user_country']: '';
$country_picker = wle_get_country_list();
?>
<p>
<label>Country<br/>
<select name="user_country">
<option value=""></option>
<?php foreach ($country_picker as $country) {
if ($user_country == $country) {
$selected = 'selected'; }
else {
$selected = '';
}
echo '<option value="' . $country . '" ' . $selected . '>' . $country . '</option>';
} ?>
</select>
</label>
</p>
<?php
}
function wle_check_country_field($sanitized_user_login, $user_email, $errors) {
if (empty($_POST['user_country'])) {
$errors->add( 'user_country_error', __('ERROR: You must choose a country.','mydomain') );
}
return $errors;
}
function register_country_field($user_id) {
if (isset($_POST['user_country'])) {
update_user_meta($user_id, 'user_country', $_POST['user_country']);
}
}
Quelle: http://www.setupmyvps.com/how-to-add-a-custom-field-to-wordpress-registration/ | WordPress Codex


Schreibe einen Kommentar