Answers for "wordpress create account function"

PHP
0

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;
}
Posted by: Guest on July-02-2021

Code answers related to "wordpress create account function"

Browse Popular Code Answers by Language