- Create new file forget-password.php and paste below given code in this.
- Create new page Forgot password and select forgetpassword template here
<?php /** * Template Name: Forgot password Template * * A custom page template without sidebar. * * The "Template Name:" bit above allows this to be selectable * from a dropdown menu on the edit page screen. * */ get_header(); if( (isset($_REQUEST['update_confirm'])) AND ($_REQUEST['update_confirm']='update_confirm') ) { $newpass=md5($_POST['newpass']); $usernameemail=$_POST['useremail']; $kkey =$_POST['key']; $reseetQry =mysql_query("update wp_users set user_pass='$newpass',user_activation_key='' where user_login='$usernameemail' AND user_activation_key='$kkey'"); echo "<span class='msgg-ok'>Your password has been reset.<br> <a href='/user-login/'>Log in</a></span>"; } if( (isset($_REQUEST['update'])) AND ($_REQUEST['update']=='update')) { $username_email=$_POST['uemail']; $Qry = mysql_query("select user_login,user_email from wp_users where user_login='$username_email' OR user_email='$username_email'"); if(mysql_num_rows($Qry)!=NULL) { $forpassAry =mysql_fetch_array($Qry); $email =$forpassAry['user_email']; $user =$forpassAry['user_login']; $homeurll=home_url('/'); $autogenerate_key =crypt($username_email); //echo "update wp_users set user_pass='$newpass' ,user_activation_key='$autogenerate_key' where user_login='$username_email' OR user_email='$username_email'"; mysql_query("update wp_users set user_pass='$newpass' ,user_activation_key='$autogenerate_key' where user_login='$username_email' OR user_email='$username_email'") or die(mysql_error()); $mailmsg="Someone requested that the password be reset for the following account:\n$homeurll.\n\nUsername: $user\n\nIf this was a mistake, just ignore this email and nothing will happen.\n\nTo reset your password, visit the following address:\n$homeurll/forgot-password/?action=rp&key=$autogenerate_key&login=$user "; //echo $mailmsg; mail($email,'[The Pacifico Partnership] Password Reset',$mailmsg); echo "<span class='msgg-ok'>Check your e-mail for the confirmation link.</span>"; } else { echo "<span class='msg-errr'>Username or Email is not found.</span>"; $notfound="errror"; } } ?> <?php if($_GET['action']=='rp'){ ?> <style> .forgot_pass{display:none;} </style> <?php } if((!$_POST) OR ($notfound!='')){ ?> <div id="forget_display"> <form action="" method="post" onsubmit="return blank_field();"> <div > <label>Please enter your username or email address.You will receive a link to create a new password via email.</label><br /><br /> <div> <input name="uemail" type="text" id="uemail" onfocus="if (this.value=='Enter Username/E-mail') this.value='';" onblur="if (this.value=='') this.value='Enter Username/E-mail';" value="Enter Username/E-mail"/></div> <input type="submit" value="Get New Password"/> </div> <input type="hidden" name="update" value="update" /> </form> </div> <?php }?> <?php if( (isset($_REQUEST['action'])) AND ($_REQUEST['action']=='rp')) {?> <div> <form action="<?php echo home_url('/') ?>forgot-password/" method="post" onsubmit="return blank_pfield();"> <div> <label>Enter new password:</label><div> <input name="newpass" type="password" id="newpass"/> </div></div><br /> <div><label>Repeat password:</label><div> <input name="repeat-pass" type="password" id="repeat-pass"/> </div></div><br /> <div><label> </label> <input type="submit" value="Change password" /></div> <input type="hidden" name="update_confirm" value="update_confirm"/> <input type="hidden" value="<?php echo $_REQUEST['login'];?>" name="useremail" /> <input type="hidden" name="key" value="<?php echo $_REQUEST['key'];?>" /> </form> </div> <?php }?> <script> function blank_field() { if(document.getElementById('uemail').value=='Enter Username/E-mail') { alert("Please enter username or email"); return false; } else { return true; } } function blank_pfield() { if(document.getElementById('newpass').value=='') { alert("Please enter new password"); return false; } if(document.getElementById('repeat-pass').value=='') { alert("Please enter repeat password"); return false; } if(document.getElementById('newpass').value!=document.getElementById('repeat-pass').value) { alert("Password do not match"); return false; } return true; } </script> <?php get_footer(); ?>
Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your site is fantastic, as well as the content!. Thanks For Your article about How create new custom forget password template ? | Raghunath Gurjar .
The only thing I get is:
Parse error: syntax error, unexpected T_CLASS in …wp-content/themes/TheCorporation-child/forget-password.php on line 20
I’m minimally programmer-minded, so I tried to troubleshoot as best I could with Google searches. I replaced any nice-formatted quotes/apostrophes to plain quotes/apostrophes. I also played with the spaces. Unfortunately, many things cause that type of error. I also disabled my plugins. But it always has given me that error.
Any suggestions?
What is the your wordpress version useing in your website?
please provide me links for i can try to help you.
I’m using the latest version 3.6. Here’s my website in progress: wpdev.4xworks.com. Thank you for any help you can provide!
Hi David,
Please find code from my new blog http://blog.mrwebsolution.in/wp-content/uploads/2013/08/forgot.php.zip
We will find me in future on my new blog http://blog.mrwebsolution.in
Please like my blog page on facebook http://facebook.com/aboutraghunath
Thanks
Raghunath
It worked! Thank you! (I’m just curious — what changed?)
Maybe I spoke too soon. It doesn’t give an error, but several things are iffy. I could try to troubleshoot myself, but you can probably solve the issues faster than me.
(1) After submitting the username for a password recovery, the email subject is “[Raghunath Gurjar] Password Reset” (2) The recovery link goes back to the page using the Forgot Password template.
Can you offer any tweaks for resolving these two issues?
Hi David,
I have sent you a email regarding to both issues on your email xxxxx.a.matsumoto@gmail.com so please read my mail and reply me on same email id.
Thanks
Raghunath
After exploring a number of the blog articles on your web page, I honestly appreciate your technique of writing
a blog. I book-marked it to my bookmark webpage list and will be checking back
soon. Please visit my web site too and tell me your opinion.
Hi there, I enjoy reading through your article post.
I wanted to write a little comment to support you.
Will it override forgot password email template
Hello Sandeep,
Thanks for comment!.
Using my code you can create only own separate forgot password email template not override the default wordpress forgot password template!
I have changed the forgot password email message in your code but still I am default wordpress forgot password email message.
Hello Sandeep,
I have already tell that using my code you can create a new forgot password template not to override the defauls wordpress template!, For this you have need to create a new template as per instruction give non this post and select that template from any page from where you want to publish this
Hello,
I tried using the code you had above and also used the forgot.php you linked in your comments.
I am able to load the page to input my email address for a new password, submit and receive the email with the link to change my password. When I click the link, it shows a log in form instead of fields with ‘new password’ + ‘repeat password’.
Am I missing something? I’ve created a new page template and paste the above code and set a new page with the that template.
Thank you for your help.
Hi Alicia,
You can use same code by creating a separate template files .
If you want then i can do it for you, send me details on my email raghunath.0087@gmail.com.
Thanks
Raghunath