Skip to content

Instantly share code, notes, and snippets.

@jonyesno
Created January 29, 2012 23:04
Show Gist options
  • Save jonyesno/1701258 to your computer and use it in GitHub Desktop.
Save jonyesno/1701258 to your computer and use it in GitHub Desktop.
Loop over WordPress MU (aka Network) sites, calling a script on each via HTTP
<?php
/* example use: http://example.com/wpmu-loop.php?script=wp-fixup-tags.php */
/* see also: https://gist.github.com/1645313 */
define('WP_INSTALLING', true);
require_once('wp-load.php');
/* get_blogs() only knows about sub-domain blogs, not sub-directory blogs
it's probably just a case of appending the path column to the result */
function get_blogs() {
global $wpdb;
$query = "SELECT domain from wp_blogs";
$blogs = $wpdb->get_results($query, ARRAY_N);
return($blogs);
}
$blogs = get_blogs();
print "<pre>\n";
if ($blogs) {
print "blogs: " . count($blogs) . "\n";
foreach ($blogs as $blog) {
print $blog[0] . "\n";
ob_flush();
if (!empty($_GET['script'])) {
print file_get_contents("http://" . $blog[0] . "/" . $_GET['script']);
print "\n";
ob_flush();
}
}
}
print "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment