我打电话时使用的是Wordpress 4.5.3wp_insert_user, 它可以正常工作,用户可以正常创建,但它不会返回ID,甚至不会返回错误。
测验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?
然后我打开了wp-includes/user。php并编辑了以下内容:
$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
我成功地编辑了用户。php,但我不想在更新Wordpress网站时弄乱核心,以免出现问题。
有人能确认这是一个bug,还是我做错了什么吗?