How create new custom forget password template ?


  1. Create new file forget-password.php and paste below given code in this.
  2. 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>&nbsp;</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(); ?>

Advertisements

Sr. Software Engineer

Posted in PHP, Wordpress
16 comments on “How create new custom forget password template ?
  1. Baju bayi says:

    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 .

  2. David says:

    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?

  3. Raghunath (Web Freelancer) says:

    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

  4. 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.

  5. Harper says:

    Hi there, I enjoy reading through your article post.
    I wanted to write a little comment to support you.

  6. Sandeep says:

    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!

      • Sandeep says:

        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

  7. Alicia says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: