[wp-hackers] Check if the administrator is logged in

kaiiser 24-7 at gmx.net
Wed Mar 31 16:53:38 UTC 2010


> I am developing a plugin where I need to do this. How do you check if
> the administrator is logged in?

If you check the capabilities of the current user (global
$current_user;) with current_user->allcaps; you will get a list of all
capabilities as an array.

To get a viewable result try this:
global $current_user;
$cur_user_allcaps = $current_user->allcaps;
  if(!empty($cur_user_allcaps)) {
    ksort($cur_user_allcaps);
    foreach($cur_user_allcaps as $key => $val) {
      if($val == 1) {
        echo $key . " = Yes; ";
      } elseif($cur_user_allcaps_value == 0) {
        echo $key . " = No; ";
      }
    }
  } else { echo "<i>EMPTY (There are no assigned capabilities)</i>"; }

AND: More easy: if(current_user_can('administrator')) { echo "is
admin"; } else { echo "is no admin"; }


More information about the wp-hackers mailing list