1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | < a class = "Forgot" data-toggle = "modal" data-target = "#myModal" >< small > Forgot Password?</ small ></ a > <!--bootsrap modal html--> < div class = "modal fade" id = "myModal" tabindex = "-1" role = "dialog" aria-labelledby = "myModalLabel" data-keyboard = "false" data-backdrop = "static" > < div class = "modal-dialog" role = "document" > < div class = "modal-content" > < div class = "modal-header" > < div class = "close" data-dismiss = "modal" aria-label = "Close" >< span aria-hidden = "true" >×</ span ></ div > < h4 class = "modal-title" id = "myModalLabel" >Forgot Password</ h4 > </ div > < div class = "modal-body" > < div id = "ForgotMessage" ></ div > < form method = "post" id = "ForgotForm" action = "" > < fieldset > < p >Please enter your email address. You will receive a link to create a new password via email.</ p > < p >< label for = "user_login" >E-mail:</ label > < input type = "email" name = "user_login" id = "user_login" value = "" required = "" ></ p > < p > < input type = "hidden" name = "action" id = "forgotaction" value = "reset" > < input type = "button" value = "Get New Password" class = "button" id = "Forgotsubmit" > </ p > </ fieldset > </ form > </ div > </ div > </ div > </ div > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | // add jquery and ajax call <script type= "text/javascript" > jQuery( function (){ jQuery( '#Forgotsubmit' ).on( 'click' , function (){ if (jQuery( '#ForgotForm' ).valid()){ var submit = jQuery( "#Forgotsubmit" ); submit.attr( "disabled" , "disabled" ).addClass( 'disabled' ); contents = { action: jQuery( '#forgotaction' ).val(), user_login: jQuery( '#user_login' ).val() }; jQuery.ajax({ type: 'POST' , data: contents, success: function (response){ submit.removeAttr( "disabled" ).removeClass( 'disabled' ); jQuery( '#user_login' ).val( '' ); if ($($.parseHTML(response)).filter( ".error" ).text() == "Invalid username or e-mail address." ){ $( '#ForgotMessage' ).html( '<p id="error">Invalid username or e-mail address.</p>' ); } else if ($($.parseHTML(response)).filter( ".error" ).text() == "There is no user registered with that email address." ){ $( '#ForgotMessage' ).html( '<p id="error">There is no user registered with that email address.</p>' ); } else if ($($.parseHTML(response)).filter( ".done" ).text() == "Check your email address for you new password." ){ $( '#ForgotMessage' ).html( '<p id="done">Check your email address for you new password.</p>' ); } else if ($($.parseHTML(response)).filter( ".error" ).text() == "Oops something went wrong updaing your account." ){ $( '#ForgotMessage' ).html( '<p id="error">Oops something went wrong updaing your account.</p>' ); } } }); } }); }); </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <?php //finally add php code. /*Forgot Password Start*/ if (! empty ( $_POST [ 'user_login' ]) && isset( $_POST [ 'action' ] ) && $_POST [ 'action' ] == 'reset' ) { global $wpdb ; $error = '' ; $success = '' ; $email = trim( $_POST [ 'user_login' ]); if ( ! is_email( $email )) { $error = 'Invalid username or e-mail address.' ; } else if ( ! email_exists( $email ) ) { $error = 'There is no user registered with that email address.' ; } else { $random_password = wp_generate_password( 12, false ); $user = get_user_by( 'email' , $email ); $update_user = wp_update_user( array ( 'ID' => $user ->ID, 'user_pass' => $random_password ) ); if ( $update_user ) { $to = $email ; $subject = 'Your new password' ; $sender = get_option( 'name' ); $message = 'Your new password is: ' . $random_password ; $headers [] = 'MIME-Version: 1.0' . "\r\n" ; $headers [] = 'Content-type: text/html; charset=iso-8859-1' . "\r\n" ; $headers [] = "X-Mailer: PHP \r\n" ; $headers [] = 'From: ' . $sender . ' < ' . $email . '>' . "\r\n" ; $mail = wp_mail( $to , $subject , $message , $headers ); if ( $mail ) $success = 'Check your email address for you new password.' ; } else { $error = 'Oops something went wrong updaing your account.' ; } } if ( ! empty ( $error ) ) echo '<p class="error">' . $error . '</p>' ; if ( ! empty ( $success ) ) echo '<p class="done">' . $success . '</p>' ; } /*Forgot Password End*/ ?> |
No comments:
Post a Comment