Skip Navigation

[Resolved] Editing user info while editing custom post

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2588259

I have a custom post type that is created when a user registers and a custom form for editing that information. Is there a way to add to that custom form fields from their user profile? Primarily looking to put email in as something they can edit and save. I saw a few posts that I could probably hack together in some way but want to find out what you'd recommend?

#2588591

Hi,

Thank you for contacting us and I'd be happy to assist.

If you'd like to allow users to edit their 'user' information, from within a 'post' edit form, it will require code customization.

For example, for each user field that you'd like to be available, you'll add a generic field in the post-edit form. You'll fill those fields with the current/existing value from the user, as the default value, but the users will be able to make changes to these.

Once, the form is submitted, you can process and save those generic field values, in the respective user field, through the custom function attached to the 'cred_save_data' hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2588973

Thanks.

I added the following the form and it displays (has a lot of data I'm sure not needed but first wanted it working). Then added the following code in the theme. But it's not saving. Probably close but can you let me know what I missed?

	<div class="form-group">
		<label for="%%FORM_ID%%_email-address">[cred_i18n name='email-address']What is your email?[/cred_i18n]</label>
		<div class="js-wpt-field-items js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="user_email">
<input type="text" id="cred_form_885_1_1_user_email" name="user_email" value="[wpv-user field="user_email"]" class="form-control wpt-form-textfield form-textfield textfield" output="bootstrap" preset_value="" urlparam="" preview="" previewsize="" select_label="" edit_label="" value_escape="" make_readonly="" placeholder="" select_text="" data-wpt-type="textfield" data-wpt-id="cred_form_885_1_1_cred_form_885_1_1_user_email" data-wpt-name="user_email">
</div>

then in the functions.php added:

add_action('cred_save_data_885', 'save_user_profile_data_885',10,2);
function save_user_profile_data_885($post_id, $form_data)
{
        $current_user = wp_get_current_user();
    	  if (isset($_POST['user_email']) && $_POST['user_email'] !== $current_user->user_email) {
          wp_update_user( array(
            'ID' => $current_user->ID,
            'user_email' => $form_data[ 'user_email' ]
          ) );
        }

}
#2590911

Thanks for writing back.

During troubleshooting, I noticed this line in your code:


'user_email' => $form_data[ 'user_email' ]

This line should be changed to get the value from the $_POST['user_email'] instead:


'user_email' => $_POST['user_email']

After this change, the code works on my test website.

#2591201

Thanks. I changed it elsewhere but totally missed that. Duh!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.