Skip to content

Instantly share code, notes, and snippets.

@jprieton
Last active August 29, 2015 14:01
Show Gist options
  • Save jprieton/98618902388381c60fab to your computer and use it in GitHub Desktop.
Save jprieton/98618902388381c60fab to your computer and use it in GitHub Desktop.
Inicio de sesion en WordPress
<?php
function jpb_login() {
$user_login = filter_input(INPUT_POST, 'user_login');
$user_password = filter_input(INPUT_POST, 'user_password');
$remember = (bool) filter_input(INPUT_POST, 'remember');
if (!empty($user_login) && !empty($user_password)) {
$creds = array();
$creds['user_login'] = $user_login;
$creds['user_login'] = $user_password;
$creds['remember'] = $remember;
$user = wp_signon($creds, false);
if (is_wp_error($user)) {
// Do something if is incorrect
return FALSE;
} else {
echo '<script type="text/javascript">window.location = "' . home_url() . '";</script>';
return TRUE;
}
}
}
// run it before the headers and cookies are sent
add_action('after_setup_theme', 'jpb_login');
<form action="" method="post">
<label for="user_login">user_login</label>
<input type="text" name="user_login" id="user_login">
<label for="user_password">user_password</label>
<input type="password" name="user_password" id="user_password">
<label for="remember">remember</label>
<input type="checkbox" name="remember" id="remember">
<input type="submit">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment