I need to rehash the password which the user entered during Wordpress registration (I use WooCommerce)
I'm successfully able to do this with the following:
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
if ( isset( $_POST['password'] ) ) {
update_user_meta($user_id, 'user_pass2', password_hash($_POST['password'], PASSWORD_DEFAULT));
}
}
However, I need to do this for 2 more occasions, profile update and reset password
I wrote:
function my_profile_update( $user_id ) {
if ( ! isset( $_POST['password'] ) || '' == $_POST['password'] ) {
return;
}
update_user_meta($user_id, 'user_pass2', password_hash($_POST['password'], PASSWORD_DEFAULT));
$x = $_POST['password'];
echo '<script language="javascript">';
echo 'alert('.$x.')';
echo '</script>';
// password changed...
}
add_action( 'profile_update', 'my_profile_update' );
It doesn' work at all.
UPDATE
function my_profile_update( $user_id ) {
update_user_meta($user_id, 'user_pass2', (string) $_POST['password']);
// password changed...
}
add_action( 'profile_update', 'my_profile_update' );
It works but $_POST['password']
or $_POST['pass1']
returns nothing.
personal_options_update
action instead of (or in addition to)profile_update
. – butlerblog Mar 29 '19 at 2:34