Thursday, May 14, 2015

Wordpress- Login user programmatically

Wordpress- Login user  programmatically

         
function custom_login() {
 $creds = array();
 $creds['user_login'] = 'username here';
 $creds['user_password'] = 'password here';
 $creds['remember'] = true;
 $user = wp_signon( $creds, false );
 if ( is_wp_error($user) )
  echo $user->get_error_message();
}
// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );

No comments :

Post a Comment