Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    To update other meta fields, you can hook a function to wpmem_post_register_data and use update_user_meta() to save any additional fields.

    Thread Starter Trisy123

    (@trisy123)

    So I wrote this:

    add_action( 'wpmem_post_register_data', 'wp_mem_savename', 1 );
    function wp_mem_savename( $fields ) {
    
        $first_name = $fields['billing_first_name'];
        $last_name = $fields['billing_last_name'];
        $user_ID = get_current_user_id();
    
        if( (!empty($first_name)) && (!empty($last_name)) ){
            update_user_meta($user_ID, 'first_name', $first_name);
            update_user_meta($user_ID, 'last_name', $last_name);
        } else {
            return;
        }
    }

    But then I realised that the user isn’t logged in at this stage. How would I write in a user if it’s not logged in and the ID has yet to be created?

    Plugin Author Chad Butler

    (@cbutlerjr)

    How would I write in a user if it’s not logged in and the ID has yet to be created?

    At the point of wpmem_post_register_data, the user has been created. The ID is in the fields array that is passed with the action.

    This was mentioned in the documentation be perhaps wasn’t stated as clearly as it could be. I’ve updated it the new format I am changing all hook documentation to, which contains a lot more info.

    Thread Starter Trisy123

    (@trisy123)

    Okay it works! Sadly I had to put it straight into my login hook or it wouldn’t work. Now I just need to figure out how to get my notify mail rolling again.

    Great documentation btw! Very useful!

    add_action( 'wpmem_post_register_data', 'my_registration_hook', 1 );
    function my_registration_hook( $fields ) {
    	$creds = array();
    	$creds['user_login']    = $fields['username'];
    	$creds['user_password'] = $fields['password'];
    	$creds['remember']      = false;
    
        $first_name = $fields['billing_first_name'];
        $last_name = $fields['billing_last_name'];
    
        update_user_meta($fields['ID'], 'first_name', $first_name);
        update_user_meta($fields['ID'], 'last_name', $last_name);
    
    	$user = wp_signon( $creds, is_ssl() );
    	if ( ! is_wp_error( $user ) ) {
    	wp_redirect( $_SERVER['REQUEST_URI'] );
    		exit();
    	} else {
    		return "loginfailed";
    	}
    }
    Thread Starter Trisy123

    (@trisy123)

    Solved!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Save user 'name' to more fields’ is closed to new replies.