Created
May 25, 2018 17:18
-
-
Save smartdeal/d7b2a5c39c9015db1713c3f81f2c62f8 to your computer and use it in GitHub Desktop.
[Wordpress custom form for change password] #WP #CF7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action("wpcf7_before_send_mail", "zz_wpcf7_change_pwd"); | |
function zz_wpcf7_change_pwd($WPCF7_ContactForm) { | |
$wpcf7 = WPCF7_ContactForm::get_current(); | |
if (3496 == $WPCF7_ContactForm->id()) { | |
$submission = WPCF7_Submission::get_instance(); | |
if ($submission) { | |
$data = $submission->get_posted_data(); | |
if (empty($data)) | |
return; | |
$pwd_old = $data['pwd-old']; | |
$pwd_new = $data['pwd-new']; | |
$pwd_user = $data['usernm']; | |
$user = get_user_by( 'login', $pwd_user ); | |
if (!empty($user)) { | |
if (is_old_pwd_ok($user->ID,$pwd_old)) { | |
$mail = $wpcf7->prop('mail'); | |
$mail['recipient'] = $user->user_email; | |
$wpcf7->set_properties(array("mail" => $mail)); | |
wp_set_password($pwd_new, $user->ID); | |
add_filter("wpcf7_ajax_json_echo", function ($response, $result) { | |
$response["status"] = "mail_sent"; | |
$response["message"] = "Пароль изменен и отправлен вам на почту"; | |
return $response; | |
}); | |
} else { | |
add_filter("wpcf7_ajax_json_echo", function ($response, $result) { | |
$response["status"] = "mail_failed"; | |
$response["message"] = "Неверный старый пароль"; | |
return $response; | |
}); | |
add_filter('wpcf7_skip_mail', '__return_true'); | |
} | |
} else { | |
add_filter('wpcf7_skip_mail', '__return_true'); | |
} | |
return $wpcf7; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment