Created
March 7, 2011 03:41
-
-
Save jeremyboggs/858033 to your computer and use it in GitHub Desktop.
Logic to run whatever activation scripts a WP plugin needs if activated network-wide.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function activation() { | |
global $wpdb; | |
// If we've got a multisite instance of WP | |
if (function_exists('is_multisite') && is_multisite()) { | |
// check if it is a network activation | |
if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) { | |
// Save our current blog | |
$current_blog = $wpdb->blogid; | |
// Get all blog ids | |
$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs")); | |
// Loop through each blog ID, switch to it, and run whatever code our plugin needs during activation. | |
foreach ($blogids as $blog_id) { | |
// Switch to the next blog. | |
switch_to_blog($blog_id); | |
// Put your activation code here. This will run for each blog on the network. | |
} | |
// Switch back to the original blog. | |
switch_to_blog($current_blog); | |
return; | |
} | |
} | |
// Put your activation code here. This will only run for a non-networked WP install. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment