Skip to content

Instantly share code, notes, and snippets.

@gicolek
Last active June 27, 2024 12:21
Show Gist options
  • Save gicolek/07e7d48c66611331bcc3 to your computer and use it in GitHub Desktop.
Save gicolek/07e7d48c66611331bcc3 to your computer and use it in GitHub Desktop.
Gravity Forms Pre Submission Hook for
<?php
// make sure to change 5he prefix to the one you are using with your forms
add_action( "gform_pre_submission_4", "wp_doin_edit_pre_submission" );
/**
* @hook gform_pre_submission_4
*/
function wp_doin_edit_pre_submission( $form ) {
// get the user created arguments and store them in an array
// note: you may need to alter these, as in case of your numbers, the input_{number} numbers may vary
$args = array(
'email' => sanitize_email( $_POST['input_2'] ),
'fname' => sanitize_text_field( $_POST['input_3'] ),
'old_pass' => sanitize_text_field( $_POST['input_4'] ),
'password' => sanitize_text_field( $_POST['input_29'] ),
);
// use fictional function to add order
wp_doin_update_user( $args );
}
/**
* Utility to update the user given a number of arguments
*/
function wp_doin_update_user( $args ) {
if ( defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] ) )
return;
// let's make sure this form doesn't run when we are viewing the page while being logged out
if( !is_user_logged_in() )
return;
// update user email
if( !empty( $args['email'] ) ){
$user_id = wp_update_user( array( 'ID' => get_current_user_id(), 'user_email' => $args['email'] ) );
}
// update user pass
if( !empty( $args['password'] ) ){
$user_id = wp_update_user( array( 'ID' => get_current_user_id(), 'user_pass' => $args['password'] ) );
}
// update user first name
if( !empty( $args['first_name'] ) ){
$user_id = wp_update_user( array( 'ID' => get_current_user_id(), 'user_pass' => $args['first_name'] ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment