Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bappi-d-great/e4048f7826c994ae1f3c to your computer and use it in GitHub Desktop.
Save bappi-d-great/e4048f7826c994ae1f3c to your computer and use it in GitHub Desktop.
Show subsite admin info in front end
<?php
/*
* Use [show_subsite_admin]
*/
function show_subsite_admin_func( $atts ) {
$a = shortcode_atts( array(
'exclude' => ''
), $atts );
$sites = wp_get_sites( array( 'limit' => 5000 ) );
$html .= '<table width="100%" cellspacing="0" cellpadding="0">';
$html .= '<tr>';
$html .= '<th>Site Name</th>';
$html .= '<th>Admin</th>';
$html .= '<th>Email</th>';
$html .= '<th>Bio</th>';
$html .= '</tr>';
foreach( $sites as $site ) {
if( $site['blog_id'] == 1 ) continue;
switch_to_blog( $site['blog_id'] );
$html .= '<tr>';
$html .= '<td><a href="' . site_url() . '" target="_blank">' . get_bloginfo( 'name' ) . '</a></td>';
$user = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
$html .= '<td>' . $user->display_name . '</td>';
$html .= '<td>' . get_bloginfo( 'admin_email' ) . '</td>';
$html .= '<td>' . $user->description . '</td>';
$html .= '</tr>';
restore_current_blog();
}
$html .= '</table>';
return $html;
}
add_shortcode( 'show_subsite_admin', 'show_subsite_admin_func' );
<?php
<?php
/*
* Use [show_subsite_admin]
*/
function show_subsite_admin_func( $atts ) {
$a = shortcode_atts( array(
'exclude' => ''
), $atts );
$sites = wp_get_sites( array( 'limit' => 5000 ) );
$html .= '<table width="100%" cellspacing="0" cellpadding="0">';
$html .= '<tr>';
$html .= '<th>Site Name</th>';
$html .= '<th>Admin</th>';
$html .= '<th>Email</th>';
$html .= '<th>Name</th>';
$html .= '</tr>';
foreach( $sites as $site ) {
if( $site['blog_id'] == 1 ) continue;
switch_to_blog( $site['blog_id'] );
$html .= '<tr>';
$html .= '<td><a href="' . site_url() . '" target="_blank">' . get_bloginfo( 'name' ) . '</a></td>';
$user = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
$html .= '<td>' . $user->display_name . '</td>';
$html .= '<td>' . get_bloginfo( 'admin_email' ) . '</td>';
$html .= '<td>' . $user->first_name . $user->last_name . '</td>';
$html .= '</tr>';
restore_current_blog();
}
$html .= '</table>';
return $html;
}
add_shortcode( 'show_subsite_admin', 'show_subsite_admin_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment