N
N
Nikita Pikovets2015-10-06 16:28:33
WordPress
Nikita Pikovets, 2015-10-06 16:28:33

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

3 answer(s)
M
MetaDone, 2015-10-06
@MetaDone

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

A
Alex, 2015-10-06
@mr_ko

Here is the problem for you

Call to undefined function changePassword()

H
HoHsi, 2015-10-06
@HoHsi

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

Secondly, what does this piece do?
And the error says that you did not define a function, although everything is OK according to the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question