Jump to content

WP plugin - Minor help


bgbs

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.