/** * Do a WordPress Sign in and call filters and action. Return TRUE if success, FALSE for access denied. * * @brief Signin * * @param string|int $user Any user id, user email or user login * @param string $password Password * @param bool $remember Optional. TRUE for set a cookie for next login * * @return bool */ public function signIn($user, $password, $remember = false) { $user_id = false; $email = ''; // Check user id if (is_numeric($user)) { $user_id = $user; } elseif (is_email($user)) { // Sanitize email $email = sanitize_email($user); // User exists with email $user_id = email_exists($email); } else { $user = get_user_by('login', $user); if ($user) { $user_id = $user->ID; } } if (false !== $user_id) { $user = new WPDKUser($user_id); if ($user->exists() && !in_array($user->status, array(WPDKUserStatus::DISABLED, WPDKUserStatus::CANCELED))) { // Check access $result = wp_authenticate($user->user_login, $password); if (!is_wp_error($result)) { // Clear the cookie wp_clear_auth_cookie(); // Set remember cookie wp_set_auth_cookie($user->ID, $remember); do_action('wp_login', $user->user_login, $user); // Authenticate! You are wp_set_current_user($user->ID); return true; } } } /** * Fires when a signin failure. * * @param int|string User email OR user id. * @param string $password Password. */ do_action('wpdk_singin_wrong', empty($email) ? $user_id : $email, $password); return false; }