The MU forums have moved to WordPress.org

Users of a blog (12 posts)

  1. SteveAtty
    Member
    Posted 14 years ago #

    Is there an easy way of finding out which users have author (or above) rights on a specific blog.

  2. SteveAtty
    Member
    Posted 14 years ago #

    So far the only way I can see to do it is to loop through all the users and do:

    $user = get_userdata($userid);
    $capabilities = $user->{$wpdb->prefix . 'capabilities'};

    And check that they are an adminstrator/editor etc.

    Surely there has to be a neater way?

  3. tim.moore
    Member
    Posted 14 years ago #

    Isn't there a "current_user_can" function that checks what the user can do? Let me see if I can find it again...

  4. andrea_r
    Moderator
    Posted 14 years ago #

    yeah, i think it's something like if user has cap?

  5. SteveAtty
    Member
    Posted 14 years ago #

    But what I need to do as a blog owner is work out which users have what capabilities on my blog, so its no the current user who interests me.

  6. DeannaS
    Member
    Posted 14 years ago #

    You can just steal the code from wpmu-blogs.php...

    $blogusers = get_users_of_blog( $id );
    if( is_array( $blogusers ) ) {
    foreach ( (array) $blogusers as $key => $val ) {
      $t = @unserialize( $val->meta_value );
      if( is_array( $t ) ) {
    	 reset( $t );
       	 $existing_role = key( $t );
    	}
    }
  7. SteveAtty
    Member
    Posted 14 years ago #

    Now why didn't I think about that? ;-)

  8. DeannaS
    Member
    Posted 14 years ago #

    I'm an EXCELLENT code stealer. Spelunking in the core for what I want is pretty much the first thing I think of.

  9. andrea_r
    Moderator
    Posted 14 years ago #

    :D

    that's why we like you so much.

  10. SteveAtty
    Member
    Posted 14 years ago #

    Its a pity the Codex doesn't cover it

  11. andrea_r
    Moderator
    Posted 14 years ago #

    Then write the codex page for it. :)

  12. DeannaS
    Member
    Posted 14 years ago #

    I'm not sure how the codex would cover it, exactly. It seems like a fairly intuitive thing to do. It's one of the great things about open source. You can download the source and search through it with your favorite multi-file search tool and follow the trail of functions, hooks, etc, until you find what you're looking for....

    Of course, my coworker has watched me do it and he says it makes his head spin.

About this Topic

  • Started 14 years ago by SteveAtty
  • Latest reply from DeannaS