Support

Account

Home Forums Front-end Issues Add E-Mail and Password field to frontend user form

Helping

Add E-Mail and Password field to frontend user form

  • Hi, I am desperately searching and trying to get this done. I have an acf frontend user profile form which works great for all the fields defined in the field group. But how can i additionally have the wordpress email and password field included in that form? And not only included, but so that it works and that the user can change email or password by submitting this form.

    does anyone out there have any clue how to do that? thanks for your help!

    vlo

  • Add an ACF e-mail field to your frontend form and use code below to map it to the author email field (where field_xxx should be replaced with your unique ACF-email field number):

    
    function my_acf_save_post( $post_id ) {
      // bail early if no ACF data
      if( empty($_POST['acf']) ) {
        return;
      }
    
      // bail early if editing in admin
      if( is_admin() ) {
        return;
      }
    
      if( $_POST['post_id'] != 'new' ) {
    
        $emailField = $_POST['acf']['field_xxx'];
        $wp_user_id = str_replace("user_", "", $post_id);
    
        if (isset($emailField)) {
          if (email_exists( $emailField )){
            // Email exists.
            update_field('field_5d1235aa4f58c', get_the_author_meta('user_email',$wp_user_id), $post_id);
          } else {
            $args = array(
              'ID'         => $wp_user_id,
              'user_email' => esc_attr( $emailField )
            );
            wp_update_user( $args );
          }
        }
      }
    
      // return the ID
      return $post_id;
    }
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Add E-Mail and Password field to frontend user form’ is closed to new replies.