Hi. I have for several years used wordpress for a webpage I’m running for a company. They have 200 registred users, from different branches. So when they log in to a custom subpage, they are logging in with wordpress credentials, but I need a custom form to add an extra field to choose a branch. This I had trouble with implementing for several years.
I have managed to get the redirection to work. So now when a user is logged in, the user is redirected to a “login part 2 page”, where they can choose the branch to access the page. But I want it in the custom login page, so the user don’t try to bypass the branch choosing. So I wonder if anyone have done anything similair before and can help.
My custom login/redirection now:
if ( ! is_user_logged_in() ) { // Display WordPress login form:
wp_login_form($args);
//CustomLoginForm();
exit;
}
$args = array(
‘redirect’ => “http://test.domain.com/login.php”,
‘form_id’ => ‘loginform-custom’,
‘label_username’ => __( ‘Username’ ),
‘label_password’ => __( ‘Password’ ),
‘label_remember’ => __( ‘Remember me’ ),
‘label_log_in’ => __( ‘Log in’ ),
‘remember’ => false
);
What I tried to implement:
if ( ! is_user_logged_in() ) { // Display WordPress login form:
add_action( ‘login_form_middle’, ‘CenterBranchField’ );
wp_login_form($args);
exit;
}
function CenterBranchField() {
$x = ‘<p class=”login-branch”>
<label for=”user_branch”>Butikk</label>
<select class=”select” id=”user_branch” name=”user_branch” >
<option value=”STD” selected>Standard</option>
<option value=”OTH”>Other</option>
</select></p>’;
return $x;
}
But I can’t “find” the information anywhere. So tried both $\_GET, $\_POST and “filter\_input( INPUT\_GET, “user\_branch”, FILTER\_SANITIZE\_STRING )”, without getting anything.
So I tried another after reading [developer.wordpress.org]):
function wpdocs_ref_access() {
global $error;
if ( empty( $_POST[‘user_branch’] ) ) {
$error = ‘Restricted area, please login to continue.’;
} else {
$error = $_POST[‘user_branch’];
// Execute redirect
}
}
add_action( ‘login_head’, ‘wpdocs_ref_access’ );
This also did nothing. So anyone got any tips to how I can get this to work?
[ad_2]