Personalized wordpress user registration

2

I need to register users in wordpress, and to register information of this user in another table of the database

global $wpdb;

if( count($_POST) > 0) {

$userdata = array(
    'user_login'  =>  $_POST['nome'],
    'user_url'    =>  'http://example.com',
    'user_pass'   =>  NULL, // When creating an user, 'user_pass' is expected.
    'role' => 'editor'
);

$user_id = wp_insert_user( $userdata );

    $cadastro = $wpdb->insert( 'usuarios',
                                array(
                                        'idusuarios' => $user_id,
                                        'nome' => $_POST['nome'],
                                        'idade' => $_POST['idade'],
                                        'cidade' => $_POST['cidade']
                                )
                            );
    if( $cadastro > 0 ) {
        echo "Cadastrado com sucesso!";
    } else {
        echo"Erro! não foi possível cadastrar";
    }
}

But this error appears:

  

Warning: mysqli_real_escape_string () expects parameter 2 to be string,   object given in C: \ xampp \ htdocs \ rondoloc \ wp-includes \ wp-db.php on line   1127

Errors in debug.log:

  

PHP Notice: Undefined index: name in C: \ xampp \ htdocs \ rondoloc \ wp-content \ themes \ rondoloc \ page-cadastro.php on line 13

     

PHP Notice: Undefined index: name in C: \ xampp \ htdocs \ rondoloc \ wp-content \ themes \ rondoloc \ page-cadastro.php on line 24

     

PHP

     

PHP

     

WordPress database error   Column 'name' can not be null for query INSERT INTO usuarios ( idusuarios , nome , idade , cidade ) VALUES ('', NULL, NULL, NULL)      

     

require_once ('C: \ xampp \ htdocs \ rondoloc \ wp-includes \ template-loader.php'),

     

include ('C: \ xampp \ htdocs \ rondoloc \ wp-content \ themes \ rondoloc \ page-cadastro.php')

    
asked by anonymous 17.06.2016 / 23:17

1 answer

0

There in user_pass is null ... and is saying in the comment "When a user is created, user_pass is expected ... A string ... And Null is returning in object form ... Maybe a $ _POST ['fieldName'], resolve ...

    
18.06.2016 / 03:39