• Resolved the1path

    (@the1path)


    OK so in plain english I want to code the following in WPMU:

    If current user has a blog then show banner

    So I thought perhaps the following WP method might work:

    if (current_user_can('administrator'))

    Ive also tried is_admin()

    but these only show a banner for the super network admin. I want it to show for just site admins.

    I had a quick look in the database and can see wp_user_level wp_2_user_level and wp_3_user_level does the current_user_can and is_admin function just link in with wp_user_level?

    How can I achieve this check to see if a user has a blog in my MU install? Do I need a custom sql query?

    Any help mucho appreciated

    Ta

Viewing 16 replies (of 16 total)
  • Ignore previous post. jjones7 made his own custom user_can_for_blog. Combined with the1path’s code I think this works for my case:

    function user_can_for_blog($user_id, $blog_id, $capability ) {
    
            $user = new WP_User( $user_id) ;
            $user->for_blog( $blog_id );
            $args = array_slice( func_get_args(), 2 );
            $args = array_merge( array( $capability ), $args );
            return call_user_func_array( array( &$user, 'has_cap' ), $args );
           }
    
    $user_id = $curauth->ID;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {
    echo '<p>No site yet</p>';
    } else if (user_can_for_blog($user_id, $primary_blog, edit_posts )) {
    echo '<p>Member has site</p>';
    } else {
    echo '<p>No site yet</p>';
    }

    Got things very confused. Spending too long on this…

    Any suggestions to tighten this up further? What is the primary_blog anyway?

Viewing 16 replies (of 16 total)
  • The topic ‘Test to see if user is a site admin, can it be done in MU?’ is closed to new replies.