bgbs Posted January 30, 2012 Share Posted January 30, 2012 I have a plugin that outputs username after login, I want it to display first name instead. Here is the code that does it. global $userdata,$user_identity; get_currentuserinfo(); if ($userdata->ID>0) { // User is logged in echo '<div class="login">' . $before_widget . $before_title . "Welcome ".$user_identity . $after_title . '</div>'; echo ' <ul class="login-links"> <li><a href="'.get_bloginfo('wpurl').'/wp-login.php?action=logout&redirect_to=http://'.$_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI'].'">Logout</a></li> <li><a href="'.get_bloginfo('wpurl').'/wp-admin">Dashboard</a></li> <li><a href="'.get_bloginfo('wpurl').'/wp-admin/profile.php">Profile</a></li> </ul> '; } else { // User is NOT logged in!!! echo $before_widget . $before_title . '<div class="login">Welcome Guest, <a href="'.get_bloginfo('wpurl').'/wp-admin">Login</a></div>' . $after_title; $user_identity is what outputs that username. I searched through wordpress forums and someone said I have to add $current_user->first_name to the code. The question is, where and how do I add it? I assume I would need to add it to this line global $userdata,$user_identity; But how do I properly syntax that? I tried doing it myself like this global $userdata,$user_identity = $current_user->first_name; but I'm getting syntax errors Your help is highly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/256071-wp-plugin-minor-help/ Share on other sites More sharing options...
StathisG Posted January 30, 2012 Share Posted January 30, 2012 The get_currentuserinfo function that you're using, places all the information in a global variable called $current_user. This is how you can retrieve the first name: $current_user->user_firstname If you read further down in the function's documentation, there is an example that you can use if you want to use different global values. The example is the following: <?php global $display_name , $user_email; get_currentuserinfo(); echo $display_name . "'s email address is: " . $user_email; ?> So, since you want the first name, I assume that you can get it if you replace "$user_identity" with "$user_firstname" in your code. I have not tested it, but it makes sense from what I've read in the documentation. Quote Link to comment https://forums.phpfreaks.com/topic/256071-wp-plugin-minor-help/#findComment-1312746 Share on other sites More sharing options...
bgbs Posted January 30, 2012 Author Share Posted January 30, 2012 Thanks a million, that answers it for me. Quote Link to comment https://forums.phpfreaks.com/topic/256071-wp-plugin-minor-help/#findComment-1312760 Share on other sites More sharing options...
StathisG Posted January 30, 2012 Share Posted January 30, 2012 You're welcome! Quote Link to comment https://forums.phpfreaks.com/topic/256071-wp-plugin-minor-help/#findComment-1312765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.