Skip to content

Instantly share code, notes, and snippets.

@EdHurtig
Created July 14, 2014 20:11
Show Gist options
  • Save EdHurtig/a1276d0153f9a42387f1 to your computer and use it in GitHub Desktop.
Save EdHurtig/a1276d0153f9a42387f1 to your computer and use it in GitHub Desktop.
<?php
/**
* Loops through all the blogs in the network switching blogs and calling the given function with a single site returned from wp_get_sites
*
*
* @param callable $lambda A function to execute for every single blog on the network
*/
function foreach_blog( $lambda ) {
$blogs = wp_get_sites( array( 'limit' => false ) );
foreach ( $blogs as $blog ) {
switch_to_blog( $blog['blog_id'] );
$lambda( $blog );
restore_current_blog();
}
}
@EdHurtig
Copy link
Author

Great for Debugging, fixing, and maintaining multisite networks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment