It depends on when in the serving process you need to do the redirect. If any HTML output has occurred, you can no longer use PHP to redirect, you need to use JavaScript. You could conditionally output the necessary JavaScript based on user logged in status. But the logged in status can normally be determined before any output, so wp_redirect() can be used from any action or filter hook that fires in the process before any output occurs. “init” for example. Check the status with is_user_logged_in() and redirect accordingly. After you call wp_redirect(), call exit() to terminate the current process.
]]>function wpms_one_blog_only($active_signup) {
// get the array of the current user's blogs
$blogs = get_blogs_of_user( get_current_user_id() );
// all users may be members of blog 1 so remove it from the count, could be a "Dashboard" blog as well
if ($blogs["1"]) unset($blogs["1"]);
//if the user still has blogs, disable signup else continue with existing active_signup rules at SiteAdmin->Options
$n = count($blogs);
if(n > 0){
$active_signup = 'none';
echo '';
} else {
$active_signup = $active_signup;
}
return $active_signup; // return "all", "none", "blog" or "user"
}
add_filter('wpmu_active_signup', 'wpms_one_blog_only');
[Moderator Note: Code fixed. To ensure your code is usable for possible testing by others, always enclose your code in `backticks`
, or use the ‘code’ button.]
There are a couple minor corrections, then your code appears to work correctly. First, the Blog 1 line should be:
if ( isset( $blogs[1])) unset( $blogs[1]);
Then the if N is greater than 0 line should be:
if ( $n > 0 ) {
If you had WP_DEBUG defined as true
in wp-config.php, you would have been notified by PHP that these changes were needed and perhaps you could have then solved this yourself ??