wordpress create account function

Solutions on MaxInterview for wordpress create account function by the best coders in the world

showing results for - "wordpress create account function"
Gaspard
21 Sep 2019
1// Simple
2wp_create_user( 'johndoe', 'passwordgoeshere', 'john.doe@example.com' );
3
4// wp_insert_user() for more fields
5$user_data = array(
6  'ID' ( null | integer ),
7  'user_pass' ( null | string ),
8  'user_login' ( null | string ),
9  'user_nicename' ( null | string ),
10  'user_url' ( null | string ),
11  'user_email' ( null | string ),
12  'display_name'( null | string ),
13  'nickname' ( null | string ),
14  'first_name' ( null | string ),
15  'last_name' ( null | string ),
16  'description' ( null | string ),
17  'user_registered'  ( null | string ),
18  'role' ( null | string ),
19  'jabber' ( null | string ),
20  'aim' ( null | string ),
21  'yim' ( null | string ),
22  'locale' ( null | string ) ,
23  //...
24);
25wp_insert_user( $user_data );
26
27// Add user meta data after wp_create_user()
28function new_user_with_metadata( $username, $password, $email = "", $meta = array() ) {
29    $meta = array(
30        'job_title' => 'developer',
31        'country' => 'United States',
32        'viaphp' => true
33    );
34
35    $user = wp_create_user( $username, $password, $email );
36
37    if ( ! is_wp_error( $user ) ) {
38        foreach( $meta as $key => $val ) {
39            update_user_meta( $user, $key, $val );
40        }
41    }
42
43    return $user;
44}
45