Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Last active June 11, 2021 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzkmx/e0c9c99c9a7685a10c25b3ee0b42d12d to your computer and use it in GitHub Desktop.
Save tzkmx/e0c9c99c9a7685a10c25b3ee0b42d12d to your computer and use it in GitHub Desktop.
basic passwordless login wordpress
<?php
require __DIR__ . '/../wp-load.php';
// si envías token, antes de esta línea tendrías que validar que el token es vigente, y de ahí obtener el token del usuario directo
if(!isset($_POST['email'])) {
$email = $_POST['email'];
}
$user = get_user_by('login', $email);
if (is_null($user)) {
invalidAuth();
}
$userId = $user->ID;
wp_clear_auth_cookie();
wp_set_current_user ( $userId );
wp_set_auth_cookie( $userId );
function invalidAuth() {
http_response_code(401);
echo "No se encontró usuario registrado como Socio\n";
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment