Support

Account

Forum Replies Created

  • Thanks a bunch, this was very helpful! 🙂

  • Thanks John.

    I’m not sure how to get the saved field key to run my check using acf/settings/load_json?

    Sami.

  • <?php if(username_exists( $username )){
    //do something
    } ?>
    <?php if(email_exists( $email )){
    //do something
    } ?>

    Are both handy functions!

  • Thanks pal. Sorted it like this:

    function user_register_pre_save( $post_id ) {
        
    
        // check if this is to be a new post
        if( $post_id != 'new' ) {
        	
        	preg_match_all('!\d+!', $post_id, $num_id);
        	$num_id = implode(' ', $num_id[0]); 
        	$num_id = (int)$num_id;
    
        	$xuserdata = array(
    		'ID' 		   => $num_id,
    		'first_name'   => $_POST['acf']['field_567a4d0a839b3'],
    		'last_name'	   => $_POST['acf']['field_567a4d10839b4'],
    		'user_email'	   => $_POST['acf']['field_567a4c416d6c1'],
    		'display_name'  => $_POST['acf']['field_567a4d0a839b3'] . ' ' . $_POST['acf']['field_567a4d10839b4']
    		);
    
        	wp_update_user($xuserdata);
    
      		return $post_id;
        }
     	
    
     	$userdata = array(
    		'ID' 		   => $user_id,
    		'user_login'	   => $_POST['acf']['field_567a4c3c6d6c0'],
    		'user_pass'	   => $_POST['acf']['field_567a4c4c6d6c2'],
    		'user_email'	   => $_POST['acf']['field_567a4c416d6c1'],
    		'first_name'    => $_POST['acf']['field_567a4d0a839b3'],
    		'last_name'	   => $_POST['acf']['field_567a4d10839b4'],
    		'display_name'  => $_POST['acf']['field_567a4d0a839b3'] . ' ' . $_POST['acf']['field_567a4d10839b4'],
    		'role'		   => $_POST['acf']['field_567ac0b49e48b']
    	);
    
    	//register user
    	$user_id = wp_insert_user($userdata);
    	$user_id = 'user_'.$user_id;
    	return $user_id;
    }
    
    add_filter('acf/pre_save_post' , 'user_register_pre_save');
  • Oops sorry John! wp docs state that wp_insert_user should also update details if an ID is supplied, for some reason now when updating info only my custom field data is updating and not the actual wp user fields 🙁

    Im updating user details from a separate template..any idea what could be causing this? (sorry!)

        $args = array(
          'post_id'      => $user_id,
          'submit_value' => 'Update',
          'return'       => get_permalink(583),
          'uploader'     => 'wp',
          'fields'       => array(field_5683c4ad44c9e, // first name
                                  field_5683c4ba44c9f, // last name
                                  field_5677c781d76ae, // email
                                  field_5683c73b75c26, // standard employee fields
                                  field_5683c76375c27,
                                  field_5683c77b75c28,
                                  field_5683c79675c29,
                                  field_5683c7b675c2a,
                                  field_5683c7bf75c2b,
                                  field_5683c7d275c2c,
                                  field_5683c7e775c2d,
                                  field_5683c80275c2e,
                                  field_5683c81f75c2f,
                                  field_5683c83575c30,
                                  field_5683c85375c31,
                                  field_5683c86475c32)
        );
    
        acf_form($args);
  • ahhh you leggend! of course! i had previously realised i was returning the post_id instead of the user_id but it was this line that fixed it – thanks a bunch!

    $user_id = 'user_'.$user_id;

    🙂

  • Thanks for the reply John! The bit that’s confusing me is that my code is successfully creating a new user in wp – what it’s not doing is updating my custom fields for ie. First name, last name, username, email etc.

    Thanks!

Viewing 8 posts - 1 through 8 (of 8 total)