I am trying to modify the following code to register it as a meta field in the user's profile to have registration date as a meta field. This would allow me to reach the information easily and integrate with other plugins that can fetch user meta fields.
One important use of this case is when you can pass meta fields along user's information to external services or e-marketing systems.
This is the original code I am also using which I am trying to adapt. The following code is used to store last login as a meta field:
add_action('wp_login', 'set_user_last_login');
//function for setting the last login
function set_user_last_login($login) {
$user = get_userdatabylogin($login);
//add or update the last login value for logged in user
update_usermeta( $user->ID, 'last_login', current_time('mysql') );
}
I've tried using this to store the registration date in a meta field but it doesn't seem to work:
//Updating User Meta with registration date
add_action( 'user_register', 'set_user_registration_date' );
//function for setting the registration date
$users = get_users();
$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
function set_user_registration_date($registered) {
$user = get_user_by($registered);
//add or update the last login value for logged in user
update_usermeta( $registered->ID, 'registration_date', $registered->user_registered );
}
I am not a PHP coder. I try to find my way, but I don't seem to be able to get this.
I would appreciate any help or if someone has a better way to achieve this?
Thanks!
$wpdb->users
table, which is what your second block of code is re-saving.