[wp-testers] logout/signon bug?

Dion Hulse (dd32) wordpress at dd32.id.au
Fri Feb 24 04:16:46 UTC 2012


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 <ejankowski at gmail.com> 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
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers


More information about the wp-testers mailing list