Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)

Untitled

By: Viruthagiri on Mar 25th, 2012  |  syntax: PHP Brief  |  size: 0.88 KB  |  hits: 84  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Log In User
  2. function log_in_user($username, $password) {
  3.        
  4.         // Get the user based on the username from the POST
  5.         $user = parse_user($username);
  6.  
  7.         // Remove html tags from the title and content fields
  8.         $username_stripped = strip_tags($username);
  9.         $password_stripped = strip_tags($password);
  10.        
  11.         // Validate the Form Data
  12.         if(isEmptyString($username_stripped)) return new WP_Error('forgot_username', 'You forgot to enter your Username');
  13.         if(isEmptyString($password_stripped)) return new WP_Error('incorrect_password', "You forgot to enter your Password.");
  14.         if(!wp_check_password( $password_stripped, $user->user_pass ) ) return new WP_Error('incorrect_password', "You seem to have entered a wrong password.");
  15.        
  16.         wp_set_auth_cookie($user->ID, $remember);
  17.         wp_login($username_stripped, $password_stripped);
  18.                
  19.         wp_redirect(get_bloginfo('url') . '/my-account/');
  20.     exit;
  21.        
  22. }