• I’m writing a plugin and I need to be able to get all the admins’ email addresses of all the sites on a Multisite platform.

    I’ve used this “get_bloginfo( ‘admin_email’ )”, but this of course just returns the main admin’s email address (i.e. the owner, first creator of the subsite, the OG, the head honcho, etc.).

    I’m trying to get ALL the admins’ email addresses (i.e. any user who has a role set to admin on this subsite, I want their email address outputted). I will need to know which admin’s email address belongs to which subsite.

    In the spirit of “throw everything you’ve got and see what sticks”, I’ve also tried array (get_bloginfo( ‘admin_email’ )), but this just me being plain dumb ditty dumb. The output is just “Array”.

    I surmise I have to approach it by doing a search for all users on the subsite that have the role “Admin” and then get their email addresses.

    Has anyone done this already or have any ideas, thoughts, or knowledge to contribute? Is there another function I’m overlooking? Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can loop through the sites of the multisite and call get_bloginfo for each one.

    Thread Starter Elvis ImpressMe

    (@msh108)

    @joyously That would just get me the email address of the original blog admin (the creator of the subsite), but not every blog admin (i.e. each blog can have multiple admins).

    Also, get_bloginfo( ‘admin_email’ ) doesn’t contain more than one email address.

    What I’m going to do is more along these lines:
    Get the user data with $user_info = get_userdata(1) (here 1 is the user id, but I won’t necessarily use that), check if the role is equal to “Administrator” with $user_info->roles, and if so, I’ll get the email address with $user_info->user_email. With this pseudo code, I will then loop through all the sites.

    Moderator bcworkz

    (@bcworkz)

    You want emails of all users that have the Administrator role? Conveniently, all users of all sites are stored in one table. You can use WP_User_Query class to get all users of a particular role regardless of site by passing a “role” argument. You can limit returned data to just the email field by using the “fields” argument.

    Thread Starter Elvis ImpressMe

    (@msh108)

    I ended up coding this and it worked perfectly:

    $blogAdminUsers = get_users( 'role=Administrator' );
    
    	 foreach ( $blogAdminUsers as $user ) 
    	 {
    		//echo '<span>' . esc_html( $user->user_email ) . ', </span>'
    		$str .= '<span>' . esc_html( $user->user_email ) . ', </span>';
    	 }
    
    	 $str = rtrim($str, ", </span>");
    	 $str .+ '</span>';
    
    echo '<td>'.$str.'</td>';
    $str = null;
    • This reply was modified 5 years, 6 months ago by bcworkz. Reason: code fixed
    Moderator bcworkz

    (@bcworkz)

    Cool! FWIW, get_users() is a wrapper for WP_User_Query. Just sayin’ ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_bloginfo( ‘admin_email’ ) for multiple admins’ email addresses’ is closed to new replies.