Skip to content

Instantly share code, notes, and snippets.

@annalinneajohansson
Created May 18, 2015 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annalinneajohansson/e8f7a17fc00014c62b74 to your computer and use it in GitHub Desktop.
Save annalinneajohansson/e8f7a17fc00014c62b74 to your computer and use it in GitHub Desktop.
<?php
function hip_auto_login() {
/* emails with + will not work "properly", then wont be logged in with this filter */
if( isset( $_GET['u'] ) && isset( $_GET['plux'] ) && isset( $_GET['post_id'] ) ) {
$email = wp_kses( $_GET['u'],array() );
$checksum = wp_kses( $_GET['plux'],array() );
$post_id = wp_kses( $_GET['post_id'],array() );
if (!is_user_logged_in() && !empty($checksum) && !empty($email)) {
// get sha256 checksum and salt it with AUTH_KEY constant defined in wp-config.php
$real_checksum = hash('sha256', $email . AUTH_KEY);
if (!empty($email) && $real_checksum == $checksum ) {
//login
$user = get_user_by('email', $email);
$userobject = wp_set_current_user($user->ID, $email);
wp_set_auth_cookie($userobject->ID);
do_action('wp_login', $user->user_login);
$settings = (array) get_option( 'ft-schools-settings' );
$welcome_page = esc_attr( $settings['login-landing-page'] );
if( $welcome_page == "profile" ) $welcome_page = $post_id;
$redirect_to = get_permalink( $welcome_page );
header('Location: ' . $redirect_to);
die;
}
}
}
else{
$settings = (array) get_option( 'ft-schools-settings' );
$welcome_page = esc_attr( $settings['login-landing-page'] );
if( $welcome_page == "profile" ) $welcome_page = $post_id;
$redirect_to = get_permalink( $welcome_page );
header('Location: ' . $redirect_to);
die;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment