get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blog_ids as $blog_id) { switch_to_blog($blog_id); $callback($blog_id); restore_current_blog(); } } else { $blog_id = get_current_blog_id(); $callback($blog_id); } } /** * Call the provided callback on the blog with the given ID. * * @since 0.9.20 * @param int $blog_id The blog ID we are switching to. * @param callable $callback The callback to be called on the blog. */ public static function for_blog($blog_id, callable $callback) { // Check if we are really on a multisite... if(!is_multisite()) { $callback($blog_id); return; } switch_to_blog($blog_id); $callback($blog_id); restore_current_blog(); } }