Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Set site/plugin options for all blogs in a WordPress Multisite network
// I used this code snippet as part of a WordPress Multisite plugin, to allow me
// to quickly set some options for all the blogs on a WordPress Multisite
// installation.
// Also see: Automatically enable plugins in new WordPress Multisite blogs -
// This function does the actual work
function djm_update_blog($blog_id = null)
if ($blog_id) {
// Put the update code here
// For example:
$options = get_option('aioseop_options', array());
$options['aiosp_paged_format'] = ' - Page %page%';
update_option('aioseop_options', $options);
if ($blog_id) {
// This creates a page in the admin area to run this for either the current blog
// (for testing) or every blog
add_action('admin_menu', 'djm_admin_menu');
function djm_admin_menu()
'Update All Blogs',
'Update All Blogs',
function djm_update_page()
global $wpdb;
if (!empty($_POST['update_this'])) {
// Update This Blog
$message = __('Blog updated.');
} elseif (!empty($_POST['update_all'])) {
// Update All Blogs
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = '{$wpdb->siteid}'
AND archived = '0'
AND spam = '0'
AND deleted = '0'
foreach ($blogs as $blog) {
$message = __('All blogs updated.');
<div class="wrap">
<h2>Update All Blogs</h2>
<?php if ($message) { ?>
<div class="updated"><p><strong><?php echo $message ?></strong></p></div>
<?php } ?>
<form action="" method="post">
<p>Use this form to run the update script for this blog or all network blogs.</p>
<p><input type="submit" name="update_this" class="button" value="<?php esc_attr_e('Update This Blog') ?>" /></p>
<p><input type="submit" name="update_all" class="button" value="<?php esc_attr_e('Update All Blogs') ?>" onclick="return confirm('Are you sure you want to run the update for all blogs?');" /></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment