to create a change password page for user in WordPress
just save the code into your current theme directory
Create new page in wp-admin/page name it as change
select template “change password”
publish it. thats all its done .
codeĀ
<?php /* Template Name: change password */ global $current_user; get_currentuserinfo(); require_once( ABSPATH . WPINC . '/registration.php' ); if ( !empty($_POST) && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) { /* Update user password */ if ( !empty($_POST['current_pass']) && !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) { if ( !wp_check_password( $_POST['current_pass'], $current_user->user_pass, $current_user->ID) ) { $error = 'Your current password does not match. Please retry.'; } elseif ( $_POST['pass1'] != $_POST['pass2'] ) { $error = 'New passwords do not match. Please retry.'; } elseif ( $_POST['pass1'] = $_POST['current_pass'] ) { $error = 'New passwords and old Password should not be same.'; }elseif ( strlen($_POST['pass1']) < 6 ) { $error = 'New Password has to be minimum 6 characters'; } elseif ( false !== strpos( wp_unslash($_POST['pass1']), "\\" ) ) { $error = 'Password may not contain the character "\\" (backslash).'; } else { $error = wp_update_user( array( 'ID' => $current_user->ID, 'user_pass' => esc_attr( $_POST['pass1'] ) ) ); if ( !is_int($error) ) { $error = 'An error occurred while updating your profile. Please retry.'; } else { $error = false; } } if ( empty($error) ) { do_action('edit_user_profile_update', $current_user->ID); wp_redirect( site_url('/change/') . '?success=1' ); } } } ?> <?php get_header(); ?> <div class="leftContent"> <?php while ( have_posts() ) : the_post(); ?> <div class="post" id="<?php the_ID(); ?>"> <div class="postHead"> <h2><?php the_title(); ?></h2> <div class="postMeta"> </div> </div> <div class="postContent"> <?php if ( !empty($_GET['success']) ): ?> <div class="message-box message-success"> <span class="icon-thumbs-up"></span> Profile updated successfully! </div> <?php endif; ?> <?php if ( !empty($error) ): ?> <div class="message-box message-error"> <span class="icon-thumbs-up"></span> <?php echo $error; ?> </div> <?php endif; ?> <form method="post" id="adduser" action=""> <table> <tr> <td> <label for="current_pass">Current Password</label> </td> <td> <input class="text-input" name="current_pass" type="password" id="current_pass"> </td> </tr> <tr> <td> <label for="pass1">New Password</label> </td> <td> <input class="text-input" name="pass1" type="password" id="pass1"> </td> </tr> <tr> <td> <label for="pass2">Confirm Password</label> </td> <td> <input class="text-input" name="pass2" type="password" id="pass2"> </td> </tr> </table> <?php // action hook for plugin and extra fields do_action('edit_user_profile_update', $current_user); ?> <p class="form-submit"> <input name="updateuser" type="submit" id="updateuser" class="submit button" value="Update profile"> <input name="action" type="hidden" id="action" value="update-user"> </p> </form> <?php endwhile; ?> </div><!-- .main-column --> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>