If you want something to display in the footer, you first need to hook it into the footer to display it. So that would look like this:
function myLog() {
echo 'test';
}
add_action('wp_footer','myLog');
However, this is not at all connected to the data you want, which is when a new user creates a new site. The wpmu_new_blog
action is deprecated so use the wp_initialize_site
hook instead.
When this hook fires, it will not output information into the footer because it’s processing information. So really, this step is just saving the information somewhere.
/**
* Function for `wp_initialize_site` action-hook.
*
* @param WP_Site $new_site New site object.
* @param array $args Arguments for the initialization.
*
* @return void
*/
function saveLog( $new_site, $args ) {
// Do something
}
add_action('wp_initialize_site','saveLog',20,2);
Since there are two events happening, that’s why you need to access two hooks. So to put it all together (this is untested, I’m literally just writing this code here)
/**
* Function for `wp_initialize_site` action-hook.
*
* @param WP_Site $new_site New site object.
* @param array $args Arguments for the initialization.
*
* @return void
*/
function saveLog( $new_site, $args ) {
// Get the info from the newly created site
$newInfo = array(array(
'blog_id' => $new_site->get('id'),
'domain' => $new_site->get('domain')
));
//Get previous log info from the Transients API
$log = get_transient('new_site_log');
if(is_array($log)) {
//Merge if it exists
$log = array_merge($log,$newInfo);
} else {
//Set new if it doesn't
$log = $newInfo;
}
//Save the log to the Transients API
set_transient('new_site_log',$log,DAY_IN_SECONDS);
}
add_action('wp_initialize_site','saveLog',20,2);
function myLog() {
//Get the log info from the Transients API
$log = get_transient('new_site_log');
//If an array with stuff, loop through it
if(is_array($log) && count($log)) {
echo '<ol>';
foreach($log as i => $siteInfo) {
// Echo the info we saved
printf(
'<li>Blog ID: %s<br />Domain: %s</li>',
$siteInfo['blog_id'],
$siteInfo['domain']
);
}
echo '</ol>';
} else {
echo 'No new sites were created';
}
}
add_action('wp_footer','myLog');
This example uses the Transients API to save the info and transients expire, but you can use whatever.