Until a Cred release that allows User-Fields…
I need to do as the title says, have the user input or update their email address that is in the user profile. This is the solution I came up with:
1 – CREATE A CUSTOM FIELD: 'tempcredemail'
2 – IN THE CRED FORM:
<!-- ******* GET USER EMAIL ******** --> <!-- Inputs to temporary metafield, then Cred Save Hook calls custom action that saves to 'user_email' in profile --> <p>Input your correct email</p> [cred_field field="tempcredemail" post="classifieds" value="[wpv-current-user info="email"]" urlparam=""]
3 – IN FUNCTIONS.PHP
// •••••• GET USER EMAIL UPDATED BY USER IN CRED FORM •••••• // add_action('cred_save_data', 'save_useremail_fromcred',10,2); function save_useremail_fromcred($post_id, $form_data) { //* Check if its CredForm - In this case it's #53213 *// if ($form_data['id']==53213) { if (isset($_POST['wpcf-tempcredemail'])) { // Save new email into _users_table // $user_id = get_current_user_id(); wp_update_user( array ( 'ID' => $user_id, 'user_email' => $_POST['wpcf-tempcredemail'] ) ) ; } } }
ALL OF THIS WORKS.
I'm just wondering if it's really necessary to create a dummy field in order to later post to the user field. Is my solution the best or is there a cleaner method?
- – - – - – - – - – - – - – - – - – - – - – - – - – - – - –
Note for others trying to follow this:
In #2, The Post= should be set to whatever your postype is.
#3 – make sure to change the Form ID # to YOUR forms ID#