Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Hi Benjamin,

    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.

    I seem not to get you, are you getting any error when users try to login, provide your website address so i can see the issue

    Thread Starter benjaminsaarde

    (@benjaminsaarde)

    Hi,
    thanks a lot for the answers, I’ve been struggling with it for a few hours, but i just can’t make it work. The thing is that i only want people to be able to register one blog per account. I found this code on the web, but I just cant make it work, so I thought of just redirecting logged in users away from the wp-signup page. Any idea?
    The code which is not working:

    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.]

    • This reply was modified 6 years, 6 months ago by bcworkz.

    Are you getting any error, what is your website url

    Moderator bcworkz

    (@bcworkz)

    I fixed the formating of the code you posted so we can test it. See the note I added in your last reply. The forum’s parser mangles your code if you don’t do as suggested.

    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 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘restricted page acces’ is closed to new replies.