Last active
November 27, 2020 10:33
-
-
Save MaryOJob/0d73fa529bbd8ad68ff74103b1f57f60 to your computer and use it in GitHub Desktop.
Add a Checkbox to Login Page on a WordPress Website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Do not copy this line please. | |
/* | |
* Please add the below code to your custom plugin or Code Snippets Plugin by following this guide: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
// As part of WP authentication process, call our function | |
add_filter('wp_authenticate_user', 'wp_authenticate_user_acc', 10, 2); | |
function wp_authenticate_user_acc($user, $password) { | |
// See if the checkbox #login_accept was checked | |
if ( isset( $_REQUEST['login_accept'] ) && $_REQUEST['login_accept'] == 'on' ) { | |
// Checkbox on, allow login | |
return $user; | |
} else { | |
// Did NOT check the box, do not allow login | |
$error = new WP_Error(); | |
$error->add('did_not_accept', 'You must accept the terms and conditions' ); | |
return $error; | |
} | |
} | |
// As part of WP login form construction, call our function | |
add_filter ( 'login_form_middle', 'login_form_acc' ); | |
function login_form_acc(){ | |
// Add an element to the login form, which must be checked | |
$termsLink = '<label><input type="checkbox" name="login_accept" id="login_accept" /> I Agree to Site Terms</label>'; | |
return $termsLink; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment