• andrez

    (@andrez)


    I am a new begginer in wordpress, now i am using wordpress 2.8 beta.
    I wanna use a user permission in my plugin so i create a table named “group”, the fields in the table are “user_id” and “group”.
    When a user login and log to my plugin, i wanna know their group so the plugin will display what the user level can do / see. It will required the current user_id.

    How to get current user_id in my plugin??

    I have use this code in one of my function in my plugin :
    <?php
    global $current_user;
    get_currentuserinfo();

    echo(‘Username: ‘ . $current_user->user_login . “\n”);
    echo(‘User email: ‘ . $current_user->user_email . “\n”);
    echo(‘User level: ‘ . $current_user->user_level . “\n”);
    echo(‘User first name: ‘ . $current_user->user_firstname . “\n”);
    echo(‘User last name: ‘ . $current_user->user_lastname . “\n”);
    echo(‘User display name: ‘ . $current_user->display_name . “\n”);
    echo(‘User ID: ‘ . $current_user->ID . “\n”);
    ?>

    then it got an error :
    Fatal error: Call to undefined function get_currentuserinfo() in C:\wamp\www\wm\wp-content\plugins\wm_manager\includes\wm_manager.class.php on line 112

    Please help me to solve this.
    Thanks very much for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This should work if you omit the line that says get_currentuserinfo()… it did for me.

    Im on wordpress 2.8.4

    global $current_user;
          $ul = 'Guest';
          if ( isset($current_user) )
          {
              $ul = $current_user->user_login;
              $useremail = $current_user->user_email;
    
          }
          if ($ul=='') { $ul = 'Guest';}
          // it helps to build a string
          // of all your output when
          // coding in wordpress, this
          // way you can control when and where it goes out to the browser...
          $outstr = "Hello, ".$ul;

    ifacethoughts.net/2006/02/25/wordpress-global-variables/

    You can use one of the global variables, that’s what they’re there for, declared globally waiting to be used.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to get current user id from a plugin?’ is closed to new replies.