/** * Iterates blogs, performing an action after each switch (multisite) * * @param mixed $action Action to perform * @param mixed $args Array containing parameters to pass to the action * @internal */ private function iterateBlogsAction($action, array $args = array()) { if (!Helpers::validCallback($action)) { return; } // Perform action on the current blog first call_user_func_array($action, $args); // If in Network Admin mode, iterate all other blogs if (Helpers::isNetworkAdminMode()) { global $wpdb, $blog_id, $switched, $switched_stack; $orig_switched_stack = $switched_stack; // global $switched_stack $orig_switched = $switched; // global $switched $orig_blog_id = $blog_id; // global $blog_id $all_blog_ids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id <> %d", $orig_blog_id)); // global $wpdb foreach ($all_blog_ids as $a_blog_id) { switch_to_blog($a_blog_id); call_user_func_array($action, $args); } // Switch back to the original blog switch_to_blog($orig_blog_id); /* Reset the global $switched and $switched_stack, as we're back at the original now. * This is faster than calling restore_current_blog() after each completed switch. * See wp-includes/ms-blogs.php. */ $switched = $orig_switched; // global $switched $switched_stack = $orig_switched_stack; // global $switched_stack } }