I am trying to add a meta key to wp_usermeta but it does not work at all. The key would get value from a checkbox. I used the code from Wordpress codex tutorial and it's not adding anything. I will show you the code (it's from a woocommerce file, but I am adding this as a standard WordPress user meta data, so it really does not matter). I checked the database and there is no 'giodo' meta key in wp_usermeta. Could anyone show me what I am doing wrong?
<?php
//1. Add a new form element...
add_action('register_form','myplugin_register_form');
function myplugin_register_form (){
$giodo = ( isset( $_POST['giodo'] ) ) ? $_POST['giodo']: '';
?>
<p>
<label for="giodo"><?php _e('First Name','mydomain') ?><br />
<input type="checkbox" name="giodo" id="giodo" class="input" value="<?php echo esc_attr(stripslashes($giodo)); ?>" size="25" /></label>
</p>
<?php
}
//2. Add validation. In this case, we make sure giodo is required.
add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
if ( empty( $_POST['giodo'] ) )
$errors->add( 'giodo_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
return $errors;
}
//3. Finally, save our extra registration user meta.
add_action('user_register', 'myplugin_user_register');
function myplugin_user_register ($user_id) {
if ( isset( $_POST['giodo'] ) )
update_user_meta($user_id, 'giodo', $_POST['giodo']);
}
?>