[英]Send new password to a new database after password change/reset in Wordpress
I have two scripts working together, I need to keep user information synchronized. 我有两个脚本一起工作,我需要保持用户信息同步。 I have no issues with the username, but for the password, I have tried 2 hooks, 'password_reset' and 'check_passwords', but it is not accomplishing:
我的用户名没有问题,但是对于密码,我尝试了2个钩子,分别是'password_reset'和'check_passwords',但操作不成功:
add_action( 'password_reset', 'change_password_in_other_script', 10, 2 );
add_action( 'check_passwords', 'change_password_in_other_script', 10, 2 );
function change_password_in_other_script( $user, $new_pass ) {
// OTHER DB CREDENTIALS
global $addShareDB;
// INITIALIZE OTHER DB CONNECTION
$mydb = new wpdb( $addShareDB['dbuser'], $addShareDB['dbpass'], $addShareDB['dbname'], $addShareDB['dbhost'] );
$current_user = wp_get_current_user();
$current_username = $current_user->user_login;
$table = 'enk_account_users';
$new_password = md5( $_POST[ 'pwd' ] );
$query = "UPDATE " . $table . " SET password = '" . $new_password . "' WHERE username = '" . $current_username . "'";
$mydb->get_results( $query );
}
Is there any other hook I can use? 我还能使用其他钩子吗?
What I am trying to do is ti be able to handle the new created plain text password right after it was inserted into the wordpress database upon password reset or change. 我想做的是,能够在密码重置或更改后将新创建的纯文本密码插入到wordpress数据库中后立即对其进行处理。 So I can update it also into the database of the other framework or maybe even post it to a script in this other framework.
因此,我也可以将其更新到另一个框架的数据库中,甚至可以将其发布到另一个框架中的脚本中。
Thank you 谢谢
Yes, You can use profile_update hook to update the password. 是的,您可以使用profile_update挂钩来更新密码。
In your theme functions.php file, put profile updates hook. 在您的主题functions.php文件中,放入配置文件更新挂钩。
You can check below code for more reference. 您可以检查以下代码以获取更多参考。
function my_profile_update( $user_id )
{
if ( ! isset( $_POST['pass1'] ) || '' == $_POST['pass1'] )
{
return;
}
elseif(!$_POST['pass1'] === $_POST['pass2']){
return;
}
else
{
//call your API to update password in your framework
}
}
add_action( 'profile_update', 'my_profile_update' );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.