Last active
February 1, 2016 15:01
-
-
Save juice49/50205b9e3da3e0d49541 to your computer and use it in GitHub Desktop.
WordPress "as blog" function
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 asBlog($blogId, $function) { | |
return function(...$arguments) use($blogId, $function) { | |
switch_to_blog($blogId); | |
$output = $function(...$arguments); | |
restore_current_blog(); | |
return $output; | |
}; | |
} | |
// For PHP < 5.6: | |
function asBlog($blogId, $function) { | |
return function() use($blogId, $function) { | |
switch_to_blog($blogId); | |
$output = call_user_func_array($function, func_get_args()); | |
restore_current_blog(); | |
return $output; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment