I'm using Wordpress 4.5.3, when I call wp_insert_user, it works, user gets created normally, but it does not return the ID or even an error.
Test.php
$userdata = array(
'user_login' => esc_attr($this->username),
'user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'first_name' => esc_attr($this->first_name),
'display_name' => esc_attr($this->tagline)
);
echo "Test 1";
$register_user = wp_insert_user($userdata);
echo "Test 2"; //This does not echo. Script stops running?
I then opened wp-includes/user.php and edited this:
$user = new WP_User( $user_id );
$meta = apply_filters( 'insert_user_meta', $meta, $user, $update );
foreach ( $meta as $key => $value ) {
update_user_meta( $user_id, $key, $value );
}
foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) {
if ( isset( $userdata[ $key ] ) ) {
update_user_meta( $user_id, $key, $userdata[ $key ] );
}
}
if ( isset( $userdata['role'] ) ) {
$user->set_role( $userdata['role'] );
} elseif ( ! $update ) {
$user->set_role(get_option('default_role'));
}
wp_cache_delete( $user_id, 'users' );
wp_cache_delete( $user_login, 'userlogins' );
if ( $update ) {
do_action( 'profile_update', $user_id, $old_user_data );
} else {
return $user_id; // I ADDED THIS FOR TEST PURPOSES. IT WORKS, IT RETURNS THE ID
do_action( 'user_register', $user_id );
}
return $user_id; // THIS IS WHERE IT SHOULD RETURN THE ID
I made it work editing users.php, but I didn't want to mess with the core to avoid problems when updating my Wordpress site.
Can anyone confirm if this is a bug, or I'm doing something wrong?