Ok seems like you have a few moving parts here…
-
You want to add a new meta field (unique code) to the user meta for all users
-
You want to modify the default login form by adding an extra field… a unique code field
-
This unique code field should allow the user to login if they have provided the same unique code in the login form
-
I’m going to assume you’ve added this meta, if not, I suggest using carbon-fields to achieve this
Container::make( 'user_meta', 'Login Meta' ) ->add_fields( array( Field::make( 'text', 'unique_code', 'Unique Code' ), ));
-
To hook into the login form you’ll want to make use of the login_form action
add_action( 'login_form', function(){ echo '<input type="text" name="unique_code" placeholder="Enter your unique code here" />'; });
- Authenticating with this unique code field
you’ll then want to look at the authenticate filter which you can hook into to force authenticate the user based on this posted “unique_code” field
add_filter( 'authenticate', function( $user, $username, $password ){
//do the check for the unique_code field here,
//which should be available in the $_POST object
return $user;
});
hope this helps, cheers