Tutorial – CUSTOM USER FORGOT PASSWORD USING AJAX IN WORDPRESS

183

Let’s complete the three WordPress custom functionalities, User Custom Login, User Custom Registration and now User Reset Password without using a plugin, this post is seriously lacking in WordPress custom development, we all know many are tried to post similar tutorial but failed to provide much details, in this tutorial I’ll try and explain as simple as possible.

The aim of this tutorial is provide user to reset or create new password in a secure and easiest way

1. Enter their email or username and ask for password reset
2. They then received email containing link to reset their password
3. In the reset page, they now able to select and provide new password
4. Done

By default WordPress offer same functionality in ww.domain.com/wp-login.php, it does offer you the three functionalities, but in our case we simply use different approach with same simplicity behind.

That’s it, let’s start

HTML

Lost Password

In this form user are allowed to enter username or email and received an email containing link to reset their password.

Reset Password

In this form user are then able to enter their new selected password.

JS (theme-ajax.js)

This sends and received submitted data.

PHP

This file check submitted data and returned to JS file.

Workaround

As you’ve notice we’re simply using common WordPress code what’s new here is by using WP_Error class, though we can use our own variable for storing error and success messages, WP_Error does a pretty good job in this part.

By default wp_ajax didn’t work in front-end or submitting data to admin-ajax.php file in front-end directly, luckily WordPress has wp_localize_script() function we can use, this function localizes a registered script with data for a JavaScript variable.

Paste the below code into your functions.php file, to avoid any conflict I suggest add it in init action

Reset Password

We use reset_password to reset users password, you can find out more in WP Codex page or at wpseek.com/reset_password

If you found any glitches just let me know

Hope that helps, happy coding ^_^

Leave A Reply

Your email address will not be published.