0

well i've created a custom login page (NOT customizing orignal login page) and use the code below to log in users:

if($_POST){
    if (!empty($_POST['username']) && !empty($_POST['password'])) {
        $creds = array(
            'user_login'    => $_POST['username'],
            'user_password' => $_POST['password'],
            'remember'      => true
            );
        $login = wp_signon( $creds, false );
        if ( is_wp_error( $login ) ) {
            $exiturl = get_site_url().'/account/auth';
            header("Location: $exiturl");
            exit();
        }
} else {
    echo "access denied";
}

the logging process works just fine, BUT if an admin user logs in via this form they can not access admin panel. they login successfully and can surf the website but they can't access admin panel to do anything (writing, editing, changing settings, ....)!

is there something that i'm missing? do i need to set any cookies or something?!

3
  • "they can not access the admin panel" - what does this mean exactly? What happens when they take which particular actions exactly? Also, you're passing false to the wp_signon() function - why?
    – Paul G.
    Jul 3, 2021 at 16:35
  • thank you, i figured it was all becuase of "false" in wp_signon()
    – KoCo
    Jul 3, 2021 at 21:06
  • I suspected it might be causing you trouble if you're using HTTPS on the admin side
    – Paul G.
    Jul 3, 2021 at 21:13

1 Answer 1

0

I should have changed false to true in the line $login = wp_signon( $creds, false );

so the final working code is

if($_POST){
    if (!empty($_POST['username']) && !empty($_POST['password'])) {
        $creds = array(
            'user_login'    => $_POST['username'],
            'user_password' => $_POST['password'],
            'remember'      => true
            );
        $login = wp_signon( $creds, true);
        if ( is_wp_error( $login ) ) {
            $exiturl = get_site_url().'/account/auth';
            header("Location: $exiturl");
            exit();
        }
} else {
    echo "access denied";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.