Skip to content

Instantly share code, notes, and snippets.

@Avakulenko
Created September 15, 2015 13:05
Show Gist options
  • Save Avakulenko/9356585a0e38e33f2c3a to your computer and use it in GitHub Desktop.
Save Avakulenko/9356585a0e38e33f2c3a to your computer and use it in GitHub Desktop.
if (!empty($_POST['field-password'])) {
$default_user_id = carbon_get_theme_option('crb_default_user');
if (!$default_user_id) {
echo 'Something went wrong';
return;
}
$default_user = get_user_by('id', $default_user_id);
$errors=array();
$creds=array();
$creds['user_login'] = $default_user->data->user_login;
$creds['user_password'] = $_POST['field-password'];
$user = wp_signon( $creds, true );
if (is_wp_error($user) ) {
$errors[] = 'Incorrect Password';
} else {
wp_set_auth_cookie($user->data->ID, true);
$redirect_url = '';
$redirect_page = carbon_get_theme_option('crb_redirect_login');
if ($redirect_page) {
$redirect_url = get_permalink($redirect_page[0]);
} else {
$redirect_url = home_url('/');
}
wp_redirect( $redirect_url );
exit;
}
} elseif (!empty($_POST) && empty($_POST['field-password'])) {
$errors[] = 'Enter Password';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment