Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created December 10, 2020 09:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/6b356b7e8f0fbe0ece7854dc05a2712e to your computer and use it in GitHub Desktop.
Save andrewlimaza/6b356b7e8f0fbe0ece7854dc05a2712e to your computer and use it in GitHub Desktop.
Add a 'Show Password' on Paid Memberships Pro login page.
<?php
/**
* Add a checkbox to frontend login page of WordPress to toggle the password text visible/hidden.
*
* Add this code to a custom plugin or Code Snippets Add On: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Source: https://www.w3schools.com/howto/howto_js_toggle_password.asp
*/
function my_pmpro_show_password_login_toggle( $items, $args ) {
$items .= '<input type="checkbox" onclick="my_show_password()"> Show Password';
?>
<script>
function my_show_password() {
var x = document.getElementById("user_pass");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
<?php
return $items;
}
add_filter( 'login_form_middle', 'my_pmpro_show_password_login_toggle', 10, 2 );
@kimwhite
Copy link

To match the font settings of "remember me" add a label tag to the snippet:
Hello,

$items .= '<label><input type="checkbox" onclick="my_show_password()"> Show Password</label>';

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