Safe to use this code with Wordfence to restrict Admin login to main login form?
-
Is it safe to use this code with Wordfence to restrict admins from logging in from the WooCommerce “My Account” page, and force them to login from the main login form only?
function wpse_398884_add_admin_login_hidden_field() { echo '<input type="hidden" name="admin-login-page" value="1" />'; } add_action( 'login_form', 'wpse_398884_add_admin_login_hidden_field', 10, 0 ); function wpse_398884_restrict_admin_login_location( $user, $username, $password ) { if ( $user instanceof WP_User && ! isset( $_POST['admin-login-page'] ) ) { if ( array_intersect( (array) $user->roles, [ 'administrator' ] ) ) { return new WP_Error( 'admin-error', 'Use admin login page instead.' ); } } return $user; } add_filter( 'authenticate', 'wpse_398884_restrict_admin_login_location', 40, 3 );
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Safe to use this code with Wordfence to restrict Admin login to main login form?’ is closed to new replies.