ti-enxame.com

Como obter o administrador do site/s pelo id do blog

Eu queria mostrar o administrador do site/s não superadministrador pelo id do blog. Que gera o ID e o avatar do administrador do site. Como conseguir isso?

1
Ken

Em formato shortcode:

/**
 * Shortcode for listing all admin users of a Multisite site
 *
 * Usage: [siteadmins blog="1"]
 */
add_shortcode('siteadmins', 'wpse_55991_site_admins');

function wpse_55991_site_admins($atts, $content = null)
{   
    $site_admins = '';
    switch_to_blog( $atts['blog'] );
    $users_query = new WP_User_Query( array( 
                'role' => 'administrator', 
                'orderby' => 'display_name'
                ) );
    $results = $users_query->get_results();
    foreach($results as $user)
    {
        $site_admins .= 'ID: ' . $user->ID . '<br />';
        $site_admins .= get_avatar( $user->user_email, 150 ) . '<br /><br />';
    }
    restore_current_blog();
    return $site_admins;
}


/* - - - - - EXTRA CODE - - - - - - */

/**
 * Shortcode for listing all admin users of all Multisite sites
 *
 * Usage: [allsiteadmins]
 */
add_shortcode('allsiteadmins', 'wpse_55991_all_site_admins');

function wpse_55991_all_site_admins($atts, $content = null)
{   
    global $wpdb;
    $blogs = $wpdb->get_results($wpdb->prepare("
        SELECT blog_id
        FROM {$wpdb->blogs}
        WHERE site_id = '{$wpdb->siteid}'
        AND spam = '0'
        AND deleted = '0'
        AND archived = '0'
        AND mature = '0' 
        AND public = '1'
    "));
    $site_admins = '';
    foreach ($blogs as $blog) 
    {
        switch_to_blog( $blog->blog_id );
        $users_query = new WP_User_Query( array( 
                    'role' => 'administrator', 
                    'orderby' => 'display_name'
                    ) );
        $results = $users_query->get_results();
        $site_admins .= 'Blog ID: ' . $blog->blog_id . '<pre>' . print_r($results,true) . '</pre>';
    }
    restore_current_blog();
    return $site_admins;
}
2
brasofilo