I think I am close…this is what I am using for the front-end Membership Account (User Profile) page and if I can get this working, I can add it to the Registration page:
This is the function that saves the user meta – I’ve added the subscribe2 meta field:
global $profileuser, $user_id, $user;
if(isset($_POST['action']) && $_POST['action'] == 'update') {
if( wp_verify_nonce($_REQUEST['_wpnonce'], 'update-user_' . $user_id) ) {
$msg = '<div class="alert alert-success">' . __('Your details have been updated.','membership') . '</div>';
$user = array( 'ID' => $_POST['user_id'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'nickname' => $_POST['nickname'],
'display_name' => $_POST['display_name'],
'user_email' => $_POST['email'],
's2_subscribed' => $_POST['s2_subscribed'],
'user_url' => $_POST['url']
);
if(!empty($_POST['pass1'])) {
if(($_POST['pass1'] == $_POST['pass2'])) {
$user['user_pass'] = $_POST['pass1'];
} else {
$msg = "<div class='alert alert-error'>" . __('Your password settings do not match','membership') . "</div>";
}
}
$errors = edit_user( $user['ID'] );
$profileuser = get_user_to_edit($user_id);
if ( isset( $errors ) && is_wp_error( $errors ) ) {
$msg = "<div class='alert alert-error'>" . implode( "<br/>\n", $errors->get_error_messages() ) . "</div>";
}
} else {
$msg = "<div class='alert alert-error'>" . __('Your details could not be updated.','membership') . "</div>";
}
do_action('edit_user_profile_update', $user_id);
}
Then this is the part of the user profile form I have added:
<div class="form-element">
<label class="control-label" for="s2_subscribed"><?php _e('Email Subscription', 'membership'); ?></label>
<div class="element">
<?php $checked = (isset($profileuser->s2_subscribed) && $profileuser->s2_subscribed) ? ' checked="checked"' : ''; ?>
<input type="checkbox" class="input-checkbox" id="s2_subscribed" name="s2_subscribed" placeholder="" value="<?php echo $checked; ?>" >
</div>
</div>
The problem is if the checkbox is unchecked (i.e. if the user unsubscribes from email notifications) it is not saving that value to the user meta. Do I have the meta keys right?