@mahmoudwp can you just try with this line?
$user_signon = wp_signon($info, false);
@faiyazalam
Thanks for reply I’m so glad with this support.
When I write only this line $user_signon = wp_signon($info, false);
wp_signon returns user, but the user is not logged in will demand login by wordpress login form
I did this solution and them suggtion is add this line wp_set_auth_cookie($user->ID);
So I hope to find the solution for your plugin
@mahmoudwp I have a custom login page with ajax on one of my multisite website. I tested my plugin with that and it worked. In the custom login page, I am just using the single line i.e. $user_signon = wp_signon($info, false);
Can you share your code along with the hook?
Are you using multisite or single site.?
Can you disable all other plugins and check if my plugin works?
I’m Using single site, and I setup just three plugins All-in-One WP Migration
and WPBakery Page Builder and WP Mail SMTP
I deactivated all but still the problem I know the problem with my code so I will try to write new code
this is my code
/**************************************************
* ****** Start Sign In Page **********
* */
add_action("wp_ajax_custom_login_mt", "handle_custom_login");
add_action("wp_ajax_nopriv_custom_login_mt", "handle_custom_login");
function handle_custom_login()
{
$param = isset($_REQUEST['param']) ? trim($_REQUEST['param']) : '';
if ($param == "login_mt") {
$info = array();
$info['user_login'] = $_POST['user_login'];
$info['user_password'] = $_POST['user_pass'];
$info['remember'] = $_POST['rememberme'];
$userRole = '';
$user_signon = wp_signon($info, false);
// wp_set_auth_cookie($user_signon->ID, true);
wp_set_current_user($user_signon->ID);
$user_signon->display_name;
if ($user_signon->caps['author'] == true) {
$page_url = admin_url('admin.php?page=dashboard');
} else {
$page_url = admin_url();
}
if (is_wp_error($user_signon)) {
// get user
$user = get_user_by('login', $info['user_login']);
// check password if match
$status = 'UserPassError';
$check_password = wp_check_password($info['user_password'], $user->user_pass, $user->ID);
if ($check_password == '1') {
// Check activation
if (get_user_meta($user->ID, 'account_activated', true) == '0') {
$status = 'notVerify';
$error = 'The account has not been verified';
}
}
echo json_encode(array("status" => $status, "error" => $error));
} else {
echo json_encode(array("status" => 0, 'page_url' => $page_url));
}
}
// print_r($_REQUEST);
wp_die();
}
Thanks for your time and helping
@mahmoudwp I tested your code with a fresh WordPress v5.6.1 and default theme Twenty Twenty-One and my plugin v2.1.0. It worked fine. I tested three times. You should also try with a fresh WordPress setup that will help you to debug.
-
This reply was modified 3 years, 9 months ago by Faiyaz Alam.
I tested it now, actually it works now with me also, but earlier this line $user_signon = wp_signon($info, false);
was not working and my client complained about it that after logged in the income it asks again to log in via the WordPress form
So, I added the last line wp_set_current_user($user_signon->ID);
and I am afraid to remove it. Perhaps this problem back, so I am thinking of another way to write the code in order to make it compatible with this plugin.
Very happy with this support. Thank you for your time. I wish you more success