wordpress create account function

// Simple
wp_create_user( 'johndoe', 'passwordgoeshere', '[email protected]' );

// wp_insert_user() for more fields
$user_data = array(
  'ID' ( null | integer ),
  'user_pass' ( null | string ),
  'user_login' ( null | string ),
  'user_nicename' ( null | string ),
  'user_url' ( null | string ),
  'user_email' ( null | string ),
  'display_name'( null | string ),
  'nickname' ( null | string ),
  'first_name' ( null | string ),
  'last_name' ( null | string ),
  'description' ( null | string ),
  'user_registered'  ( null | string ),
  'role' ( null | string ),
  'jabber' ( null | string ),
  'aim' ( null | string ),
  'yim' ( null | string ),
  'locale' ( null | string ) ,
  //...
);
wp_insert_user( $user_data );

// Add user meta data after wp_create_user()
function new_user_with_metadata( $username, $password, $email = "", $meta = array() ) {
    $meta = array(
        'job_title' => 'developer',
        'country' => 'United States',
        'viaphp' => true
    );

    $user = wp_create_user( $username, $password, $email );

    if ( ! is_wp_error( $user ) ) {
        foreach( $meta as $key => $val ) {
            update_user_meta( $user, $key, $val );
        }
    }

    return $user;
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source