Answer the question
In order to leave comments, you need to log in
How to change password on WP?
You need to change the password when filling out a form consisting of 2 fields (a new password and its confirmation), the data is selected on jquery and an ajax request is made to the function.php file where we successfully get an error:
Call to undefined function chengePassword() in /home/p317367 /public_html/wp-content/themes/vault-theme/chengePassword.php
function.php code:
if (!empty($_POST['password'])) {
$password = $_POST['password'];
$userId = $_POST['user'];
changePassword($userId, $password);
echo 'pass '.$password.'user '.$userId;
}
add_action( 'init', 'changePassword' );
function changePassword($user, $pass){
wp_set_password( $pass, $user );
Tell me what's the problem?
Answer the question
In order to leave comments, you need to log in
ajax - requests in wordpress should preferably be sent to "/wp-admin/admin-ajax.php", and do not forget to pass a nonce
. As a result, it will look something like this:
add_action("wp_ajax_nopriv_chenge_password","chenge_password"); //для неавторизованных пользователей
add_action("wp_ajax_chenge_password","chenge_password"); //для авторизованных пользователей
function chenge_password(){
if (!empty($_POST['password'])) {
$password = $_POST['password'];
$userId = $_POST['user'];
wp_set_password( $password, $userId );
}
First of all, WP has a hook for AJAX requests, why are you cycling?
function nameOfFunc(){
exit;
}
add_action('wp_ajax_nameOfFunc', 'nameOfFunc');
add_action('wp_ajax_nopriv_nameOfFunc', 'nameOfFunc');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question