Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active February 27, 2024 10:57
Show Gist options
  • Save ipokkel/6098e66a21c04592c60a5a6109af07df to your computer and use it in GitHub Desktop.
Save ipokkel/6098e66a21c04592c60a5a6109af07df to your computer and use it in GitHub Desktop.
Show password on reset password page to allow user to reveal and view the password.
<?php
/**
* Password visibility toggle on the reset password page.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_show_password_toggle_reset_password() {
global $pmpro_pages;
// Bail if not on the reset password page.
if ( ! is_page( $pmpro_pages['login'] ) || empty( $_REQUEST['action'] ) || 'rp' !== $_REQUEST['action'] || empty( $_REQUEST['key'] ) ) {
return;
}
?>
<script>
jQuery(document).ready(function () {
var showPassDiv = jQuery('<div class="pmpro_reset_password-field pmpro_reset_password-field-showpass">');
var showPassCheckbox = jQuery('<input type="checkbox" id="showPasswordCheckbox">');
var showPassText = jQuery('<span> Show Password</span>');
showPassDiv.append(showPassCheckbox);
showPassDiv.append(showPassText);
jQuery('.pmpro_reset_password-field-pass2').after(showPassDiv);
// Handle the show password checkbox
jQuery('#showPasswordCheckbox').on('change', function () {
var pass1Input = jQuery('#pass1');
var pass2Input = jQuery('#pass2');
if (jQuery(this).is(':checked')) {
// Show the password in both fields
pass1Input.attr('type', 'text');
pass2Input.attr('type', 'text');
} else {
// Change back to password fields
pass1Input.attr('type', 'password');
pass2Input.attr('type', 'password');
}
});
});
</script>
<?php
}
add_action( 'wp_footer', 'my_pmpro_show_password_toggle_reset_password' );
@ipokkel
Copy link
Author

ipokkel commented Feb 27, 2024

any idea how to bypass the PMPRO reset password error?

It's best to ask support questions not related to this specific gist here: https://wordpress.org/support/plugin/paid-memberships-pro/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment