Wordpress - 我应该使用哪个挂钩通过配置文件更新和密码重置来捕获 $_POST('password')

Wordpress - Which hook should I use to capture $_POST('password') via profile update and password reset

我需要重新哈希用户在 Wordpress 注册期间输入的密码(我使用 WooCommerce)

我成功地做到了

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));
    }

}

但是我需要再执行 2 次,配置文件更新重置密码

我写了

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' );

根本不起作用

function my_profile_update( $user_id ) {

    if ( ! is_admin() ) {
       update_user_meta($user_id, 'user_pass2', (string) $_POST['password_1']);
    }
    // password changed...
}
add_action( 'profile_update', 'my_profile_update' );