The code I sent is just a test code, the real plugin is much more complicate, but yes, I don't need to just show user info, I need to log out any logged user, and then log in a new one and show some info.
So I found a solution, but again, I don't know if it is a bug or just it works like that. The solution is to use the wp_set_current_user function, like $user_obj = wp_signon($user_data, false); wp_set_current_user($user_obj->ID); Thanks On Fri, Feb 24, 2012 at 1:16 AM, Dion Hulse (dd32) <[email protected]>wrote: > Lets start from the start... I'm not even sure why you're attempting > to do it the way you are.... > Don't mess with user authentication.. unless you want to log the user > in as a user.. which is exactly what you're doing (and thus, why it > isn't working) > > You can display user meta, or any details about a user, without > logging the user in, the most obvious method of doing so, is to > instantate a new user object, and grab the data from there: > > $user = new WP_User( 'dd32' ); > echo $user->first_name . ' ' . $user->last_name; > > If for some reason you needed to switch between user accounts, there > is a function to do so, but given that switches everything including > permissions, that's just asking for someone to shoot themselves in the > foot with.. > > On 24 February 2012 02:41, Emiliano Jankowski <[email protected]> > wrote: > > Hi there! > > > > I'm having a problem with the user authentication. But I'm not totally > > sure, if it is a bug or something I'm doing wrong. > > > > Basically what I need to do is: > > > > 1 - Logout any logged user > > 2 - Sign in with a user > > 3 - Show the first/last name of the user using a shortcode > > > > So, I've made this testing plugin with some random strange behaviors. The > > result of the plugin is: > > > > FN_User1 > > Logged user: FN_User1 LN_User1 > > > > FN_User2 *as you can see here, user 2 was logged, but the shortcode > > still have user1 information* > > Logged user: FN_User1 LN_User1 > > > > FN_User1 > > Logged user: FN_User1 LN_User1 > > > > > > /* > > Plugin Name: Test > > Plugin URI: > > Description: > > Author: Emiliano Jankowski > > Version: 0.1 > > */ > > > > > > add_action("init","prueba"); > > > > function prueba(){ > > add_shortcode("filter_test","test_apply"); > > echo "<br/><br/>"; > > wp_logout(); > > $user_data["user_login"] = "user1"; > > $user_data["user_password"] = "123456"; > > $user_obj = wp_signon($user_data, false); > > echo($user_obj->first_name."<br/>"); > > $content = do_shortcode("Logged user: [filter_test] " ); > > echo($content."<br/><br/>"); > > wp_logout(); > > $user_data["user_login"] = "user2"; > > $user_data["user_password"] = "123456"; > > $user_obj = wp_signon($user_data, false); > > echo($user_obj->first_name."<br/>"); > > $content = do_shortcode("Logged user: [filter_test] " ); > > echo($content."<br/><br/>"); > > wp_logout(); > > $user_data["user_login"] = "user1"; > > $user_data["user_password"] = "123456"; > > $user_obj = wp_signon($user_data, false); > > echo($user_obj->first_name."<br/>"); > > $content = do_shortcode("Logged user: [filter_test] " ); > > echo($content."<br/><br/><br/>"); > > } > > > > function test_apply(){ > > $user = get_current_user_id(); > > $user = get_userdata($user); > > return $user->first_name." ".$user->last_name; > > } > > > > > > I hope you can help me! > > > > Thanks a lot! > > > > > > > > > > > > > > -- > > http://www.flickr.com/photos/ejankowski/ > > -- > > > > Emiliano Jankowski > > Lic. Sistemas > > _______________________________________________ > > wp-testers mailing list > > [email protected] > > http://lists.automattic.com/mailman/listinfo/wp-testers > _______________________________________________ > wp-testers mailing list > [email protected] > http://lists.automattic.com/mailman/listinfo/wp-testers > -- http://www.flickr.com/photos/ejankowski/ -- Emiliano Jankowski Lic. Sistemas _______________________________________________ wp-testers mailing list [email protected] http://lists.automattic.com/mailman/listinfo/wp-testers
