• I dont’ know if this is the right place to post but I am a total newbie to php and need some help.

    I am using wordpress and a plugin known as admin menu for it.
    my site is at http://www.jessas.com/blog/

    I would like to be able to add the following to the that menu (which is like a bar right at the top of the page).

    if a guest comes then welcome guest and ask them to register. and if someone is registered then to say welcome “username”

    I have figured out which file (sem-admin-menu.php) and where to add the welcome. but can’t figure out how to get the name from the database and add it to the file.

    On line 130 i have added welcome and then after that I think is where I would need to call the information.

    I would really appreciate all the help I can get.

    On a sidenote: I found the following script and tried it and it works in my sideabar.php file but don’t know how to implement it to the sem-admin-menu.php file.

    \
    <?php global $user_nickname;
    get_currentuserinfo();
    if ( $user_nickname<> “” ) { ?>
    Welcome <?php echo $user_nickname ?>.
    <?php } else { ?>
    Welcome Guest<?php } ?>
    \

Viewing 9 replies - 1 through 9 (of 9 total)
  • The key bit is the global variable $user_nickname. Try sticking that in in the right place. See that one line:

    Welcome <?php echo $user_nickname ?>.

    I don’t know the plugin you are using, but you said you already found the place you want to have it show up, so I assume you can give this a shot.

    Thread Starter miz

    (@miz)

    Hi thanks for the suggestion I tried that but the thing is that the plugin file which I am editing is written all within the <?php ?> tags and therefore the place I need to add it looks like this. Again i think this is where I would add it but am not sure. It would be after the Welcome, (Welcome shows up on my site as text). I don’t know if there is any way to attach the file here? but here is a link to the main plugin page
    http://www.semiologic.com/software/admin-menu/

    Code:

    if ( $user_ID )
    {
    $o .= ( user_can_create_draft($user_ID)
    ? ( "

    <li>" . __('Welcome', "") . ""
    . "</li>
    n"

    to be sure your code isn’t messed up, put it between backticks ( the key at the top left ). what is showing up looks busted. if you repost it, I’ll take a crack at the modification.

    Thread Starter miz

    (@miz)

    mastraw, thank you for the offer I really appreciate it……

    I am also including a download link for the zipped file at my site:

    http://www.jessas.com/adminmenu.zip

    I have copied a larger chunk of the code and pasted it, please let me know if you need anymore……


    function display_menu()
    {
    global $user_ID;
    global $user_level;
    global $user_nickname;
    get_currentuserinfo();
    if ( $user_nickname<> "" )
    echo $user_nickname ;

    $site_path = trailingslashit(get_settings('home'));

    $o = "";

    $o .= "<div id="sem_admin_menu">n"
    . "<ul>n";

    if ( $user_ID )
    {
    $o .= ( user_can_create_draft($user_ID)
    ? ( "<li>" . __('Welcome', "") . ""
    . "</li>n"
    . "<li>|</li>n"
    ."<li class="new_item">"
    . __('New:', 'sem-admin-menu') . " "
    . "<a href=""
    . $site_path . "wp-admin/post.php">"
    . __('Post', 'sem-admin-menu')
    . "</a>"
    . ( ( $user_level >= 5 )
    ? ( " &bull;&nbsp;"
    . "<a href=""
    . $site_path . "wp-admin/link-add.php">"
    . __('Link', 'sem-admin-menu')
    . "</a>"
    . " &bull;&nbsp;"
    . "<a href=""
    . $site_path . "wp-admin/page-new.php">"
    . __('Page', 'sem-admin-menu')
    . "</a>"
    )
    : ""
    )
    . "</li>n"
    . "<li>|</li>n" )
    : ""
    )

    I don’t have time to study the whole script, but I can give you a quick tip on the code you posted.

    if ( $user_nickname<> "" )
    echo $user_nickname ;

    That bit can be changed to add the word welcome by changing it to the following:

    if ( $user_nickname<> "" )
    echo "welcome" . $user_nickname ;

    As far as asking a guest to register, I would assume this admin bar is only visible if a person is logged in right? If it’s always visible, the above code could be modified. If it’s not always visible, you’d need to find where it decides to display it or not. Most likely where the function is called.

    Here is how that above could should be changed if the admin bar is always visible:

    if ( $user_nickname<> "" ) {
    echo "welcome" . $user_nickname ; }
    else {
    echo "please log in"; }

    You could change please log in to anything, and perhaps even code in an a tag to link to the login page.

    Thread Starter miz

    (@miz)

    How do i call the function and if you look at how the code is formatted in the page or my pasteup it’s all within one <?php ?> tag.

    So basically i need to add the calling of the function instaed of where i have typed “CALL FUNCTION IN THIS AREA BUT DON”T KNOW HOW TO?”

    But how do i format the calling of the function properly within these code specs…


    if ( $user_ID )
    {
    $o .= ( user_can_create_draft($user_ID)
    ? ( "<li>" . __('Welcome', "CALL FUNCTION IN THIS AREA BUT DON"T KNOW HOW TO?") . ""
    . "</li>n"

    I recommend you contact the author. I just don’t have enough info, and not enough time to study that plugin. Unless someone else reads this and is familiar enough to advise.

    Thread Starter miz

    (@miz)

    thank you for your help up to now… unfortunately the only support the author gives is paid support at least according to his site……… I think this is just a little thing which I have to figue out 🙂 hopefully someone else can help?

    Thanks Again

    Thread Starter miz

    (@miz)

    Well I fixed it 🙂 I had to refer to the plugin Admin bar from http://mattread.com/projects/wp-plugins/wp-admin-bar/

    Anyways for anyone interested this is what I added
    under function
    display_menu()
    I added global $user_identity;

    and then where the main stuff starts, i added….


    "<li>"
    . __('Welcome ', 'sem-admin-menu') . " "
    . "<a href=""
    . $site_path . "wp-admin/profile.php">"
    . $user_identity
    . "</a>"
    . "</li>n"

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding a logged in user’s name’ is closed to new replies.