admin管理员组文章数量:1130349
I've written a plugin to allow authentication to a WordPress install via an external API. Everything is working except the first and last names are not being set for the new WordPress user created by the plugin when a login attempt passes the external authentication.
Here's the really strange part: one of the selectable display names is the first and last names coming in from the external API.
$userdata = array( 'user_email' => $ext_user['email'],
'user_login' => $ext_user['email'],
'first_name' => $ext_user['firstName'],
'last_name' => $ext_user['lastName'],
'role' => $user_role
);
$new_user_id = wp_insert_user( $userdata );
$user = new WP_User ($new_user_id);
That's the code I'm using to create the new users. I have logged both $ext_user['firstName'] and $ext_user['lastName'] just before filling the $userdata array to ensure those values are coming through properly and they are. I can't understand how they can be in the Display Name field but the First Name and Last Name fields are blank. Can anyone help?
UPDATE: This install runs the Cimy User Extra Fields plugin. At first, I thought this might be the culprit, but I disabled it and the issue persists. Maybe that's still the problem, but I don't know how to determine. Could this plugin replace the default first and last name fields?
I've written a plugin to allow authentication to a WordPress install via an external API. Everything is working except the first and last names are not being set for the new WordPress user created by the plugin when a login attempt passes the external authentication.
Here's the really strange part: one of the selectable display names is the first and last names coming in from the external API.
$userdata = array( 'user_email' => $ext_user['email'],
'user_login' => $ext_user['email'],
'first_name' => $ext_user['firstName'],
'last_name' => $ext_user['lastName'],
'role' => $user_role
);
$new_user_id = wp_insert_user( $userdata );
$user = new WP_User ($new_user_id);
That's the code I'm using to create the new users. I have logged both $ext_user['firstName'] and $ext_user['lastName'] just before filling the $userdata array to ensure those values are coming through properly and they are. I can't understand how they can be in the Display Name field but the First Name and Last Name fields are blank. Can anyone help?
UPDATE: This install runs the Cimy User Extra Fields plugin. At first, I thought this might be the culprit, but I disabled it and the issue persists. Maybe that's still the problem, but I don't know how to determine. Could this plugin replace the default first and last name fields?
Share Improve this question asked Mar 4, 2014 at 19:10 raddevonraddevon 2134 silver badges12 bronze badges 9 | Show 4 more comments2 Answers
Reset to default 2After wp_insert_user, you could try running update_user_meta( $new_user_id, "first_name", $ext_user['firstName'] ) ;
This code works when I try it, though it generates an "undefinded variable" error (looks like you should pass a user password). However, there are a number of filters in there that could be used to manipulate the data. including pre_user_first_name and pre_user_last_name. As those fields are "meta" fields, it would also be possible to alter the data via filters run by update_user_meta(). That data is passed through update_metadata() which allows selective filtering.
I can only assume that one or more of those filters are involved in creating this issue.
I've written a plugin to allow authentication to a WordPress install via an external API. Everything is working except the first and last names are not being set for the new WordPress user created by the plugin when a login attempt passes the external authentication.
Here's the really strange part: one of the selectable display names is the first and last names coming in from the external API.
$userdata = array( 'user_email' => $ext_user['email'],
'user_login' => $ext_user['email'],
'first_name' => $ext_user['firstName'],
'last_name' => $ext_user['lastName'],
'role' => $user_role
);
$new_user_id = wp_insert_user( $userdata );
$user = new WP_User ($new_user_id);
That's the code I'm using to create the new users. I have logged both $ext_user['firstName'] and $ext_user['lastName'] just before filling the $userdata array to ensure those values are coming through properly and they are. I can't understand how they can be in the Display Name field but the First Name and Last Name fields are blank. Can anyone help?
UPDATE: This install runs the Cimy User Extra Fields plugin. At first, I thought this might be the culprit, but I disabled it and the issue persists. Maybe that's still the problem, but I don't know how to determine. Could this plugin replace the default first and last name fields?
I've written a plugin to allow authentication to a WordPress install via an external API. Everything is working except the first and last names are not being set for the new WordPress user created by the plugin when a login attempt passes the external authentication.
Here's the really strange part: one of the selectable display names is the first and last names coming in from the external API.
$userdata = array( 'user_email' => $ext_user['email'],
'user_login' => $ext_user['email'],
'first_name' => $ext_user['firstName'],
'last_name' => $ext_user['lastName'],
'role' => $user_role
);
$new_user_id = wp_insert_user( $userdata );
$user = new WP_User ($new_user_id);
That's the code I'm using to create the new users. I have logged both $ext_user['firstName'] and $ext_user['lastName'] just before filling the $userdata array to ensure those values are coming through properly and they are. I can't understand how they can be in the Display Name field but the First Name and Last Name fields are blank. Can anyone help?
UPDATE: This install runs the Cimy User Extra Fields plugin. At first, I thought this might be the culprit, but I disabled it and the issue persists. Maybe that's still the problem, but I don't know how to determine. Could this plugin replace the default first and last name fields?
Share Improve this question asked Mar 4, 2014 at 19:10 raddevonraddevon 2134 silver badges12 bronze badges 9- 1 Do you have access to the database? If yes, are the fields filled with the info? Maybe it is just a problem of listing that info in the dashboard – K Themes Commented Mar 4, 2014 at 19:43
- @KThemes I just took a look at the database, and it looks like the plugin I mentioned has hijacked the WP first and last name columns. Those don't exist in the user database at all. – raddevon Commented Mar 4, 2014 at 20:47
-
1
After wp_insert_user, you could try running
update_user_meta( $new_user_id, "first_name", $ext_user['firstName'] ) ;– czerspalace Commented Mar 4, 2014 at 21:54 - @czerspalace Your solution worked. Not sure why it came to that, but that fixed the problem. If you want to post it as an answer, I'll mark it correct. – raddevon Commented Mar 5, 2014 at 13:21
- 1 Maybe, just maybe you have some function hooked in the "pre_user_first_name" filter ($first_name = apply_filters('pre_user_first_name', $first_name);) If you wanna check and be sure if there is any function hooked in there you can use this answer: stackoverflow/questions/5224209/… – K Themes Commented Mar 7, 2014 at 11:21
2 Answers
Reset to default 2After wp_insert_user, you could try running update_user_meta( $new_user_id, "first_name", $ext_user['firstName'] ) ;
This code works when I try it, though it generates an "undefinded variable" error (looks like you should pass a user password). However, there are a number of filters in there that could be used to manipulate the data. including pre_user_first_name and pre_user_last_name. As those fields are "meta" fields, it would also be possible to alter the data via filters run by update_user_meta(). That data is passed through update_metadata() which allows selective filtering.
I can only assume that one or more of those filters are involved in creating this issue.
本文标签: plugin developmentFirst and last name fields not filled when using wpinsertuser
版权声明:本文标题:plugin development - First and last name fields not filled when using wp_insert_user 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749207970a2332886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


update_user_meta( $new_user_id, "first_name", $ext_user['firstName'] ) ;– czerspalace Commented Mar 4, 2014 at 21:54