I'm trying to build a function which run when a member is registering on my site.
I am building an extranet using the Simple LDAP login plugin to use my LDAP directory so that users connect on the extranet with the credentials they are used to using with their LDAP account.
Unfortunately, in my LDAP directory, I do not have fields that allow me to fill in the "first_name" and "last_name" fields of a my WordPress users profiles. So, as the email addresses are necessarily constituted as follows: [email protected]
, this function cuts the email address so that I can retrieve in a table the first name and the last name and, then fill in the first_name
and last_name
fields of the WordPress user with wp_update_user()
;
When users log in for the first time, they actually have no account on my WordPress site. The creation of the account is done when the connection to the extranet queries the LDAP directory. That's why I would have liked to use the user_register
action hook;
My function is in the functions.php
.
Here's the function :
add_action( 'user_register', 'fill_identity' );
function fill_identity(){
global $current_user;
wp_get_current_user();
get_currentuserinfo();
$mail_user=$current_user->user_email;
$mail_user = substr($mail_user,0,-14);
$mail_user = explode(".", $mail_user);
$prenom = $mail_user[0] = ucfirst($mail_user[0]);
$nom = $mail_user[1] = ucfirst($mail_user[1]);
var_dump($mail_user);
wp_update_user([
'ID' => $current_user->ID,
'first_name' => $prenom,
'last_name' => $nom,
]);
}
But when someone registers on my site, It changes nothing.
I have tested running the fill_identity()
function from the header.php
and the function works well, it's how I knew the problem was not my function but the add_action
. I've tried with others actions and it doesn't work.
I'm not really familiar writing my own hooks, this one is my first. However, my functions.php
contains a lot of functions that I've find for some others functionalities and it's works well.
Did you have an idea ?
var_dump(wp_get_current_user());die()
. just add after function start