function authenticate( $user_id, $user_name, $user_pass ) { global $current_user; $current_user = WP_User( $user_id ); $return = wp_login( $user_name, $user_pass ); if ( $return ) $return = wp_set_cookie( $user_name, $user_pass ); else return new WP_Error( 'Something went wrong while logging in!' ); if ( $return ) return true; else return new WP_Error( 'Something went wrong while setting a cookie!' ); }