login – User not able to sign in after wp_authenticate() and wp_signon() wordpress
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
6 times
<?php
global $user_id;
global $wpdb;
if(!$user_id){
if($_POST){
$username = $wpdb->escape($_POST['email']);
$password = $wpdb->escape($_POST['password']);
$login_array = array();
$login_array['user_login'] = $username;
$login_array['user_password'] = $password;
$verifyUser = wp_signon($login_array,false);
echo var_dump($verifyUser);
} else{
echo "
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=AIzaSyD-q6DH3L2eG9pzQYxUZ9YzIzIuJbqJAGU&ver=3.exp"></script>
<div class="container-fluid" id='grad1'>
<div class="row justify-content-center mt-0">
<div class="col-11 col-sm-9 col-md-7 col-lg-6 text-center p-0 mt-3 mb-2">
<div class="card px-0 pt-4 pb-0 mt-3 mb-3">
<div class="row">
<form id='loginform' method='post' action=''>
<fieldset>
<div class="form-card">
<label>Username</label>
<input
id='username'
placeholder="Please enter your email"
type="text"
class="form-control"
name="email"/>
<label>Password</label>
<input
type="password"
class="password"
name="password"
class="form-control"
placeholder="Enter password"
id='password'/>
<input
type="submit"
name="loginButton"
id='loginButton'
value="Login"/>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<a id='forgottenPassword' href="forgottenPassword">Forgotten Password?</a>
<a id='registration' href="registration">Click here to sign up</a>
</div>
</div>
</body>
</html>";
}
}
?>
function isUserActivated($username){
// First need to get the user object
$user = get_user_by('login', $username);
if(!$user) {
$userID = $user->ID;
if(!$user) {
echo $user;
return $username;
}
}
$userStatus = get_user_meta($user->ID, 'Account Verified', true);
$userStatus = 1;
$login_page = home_url('/log-in-failed/');
if($userStatus == 0){
wp_redirect($login_page . "?login=failed");
wp_redirect($login_page);
return 0;
exit;
} else{
return 1;
}
}
add_action('wp_authenticate', 'isUserActivated');
Sheran Malik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
default

Leave an answer