Only members can access entire site

Is it possible to allow users to only sign up when getting a website, so not allow just an account to be created?

Also, is it possible to only allow access to all pages of the site, except the home page, to those with an active membership?

  • Michael Bissett

    Hey @Dark Scream, hope you're doing well today! :slight_smile:

    Is it possible to allow users to only sign up when getting a website, so not allow just an account to be created?

    We can hide the option to only create an account by adding this code snippet as an mu-plugin:

    <?php
    function wpmudev_hide_user_and_site_signup_options_fix() {
    	echo '<style>
    		#setupform > p > input#signupblog {
    			display: none;
    		}
    
    		#setupform > p > label.checkbox {
    			display: none;
    		}
    
    		#setupform > p > input#signupuser {
    			display: none;
    		}
    	</style>';
    }
    add_action( 'signup_header', 'wpmudev_hide_user_and_site_signup_options_fix' );

    Also, is it possible to only allow access to all pages of the site, except the home page, to those with an active membership?

    This would be the home page for the main site, right?

    Hmm... the thing is, Pro Sites tracks whether a site is a Pro Site, it doesn't make a user a premium user (like Membership or Protected Content does, though they are registering for memberships, which is a different story here...).

    Could you elaborate on why you're looking to protect the home page like this?

    Please advise,
    Michael

  • Moonworks

    I'm adding this to the snippets plugin, but it is removing some of the code, making it:

    function wpmudev_hide_user_and_site_signup_options_fix() {
    	echo '<style>
    		#setupform > p > input#signupblog {
    			display: none;
    		}
    
    		#setupform > p > label.checkbox {
    			display: none;
    		}
    
    		#setupform > p > input#signupuser {
    			display: none;
    		}
    	</style>';
    }
    add_action( 'signup_header', 'wpmudev_hide_user_and_site_signup_options_fix' );
  • Ash

    Hello @Dark Scream

    I hope you are well today.

    Is it possible to allow users to only sign up when getting a website, so not allow just an account to be created?

    You need to create a custom signup page. Also, you need to include all available hooks in the custom sign up page. Here is a tutorial how you can enable a custom registration page: https://www.chriswiegman.com/2010/02/using-a-custom-wp-signup-page-with-wordpress-mu/

    Also, is it possible to only allow access to all pages of the site, except the home page, to those with an active membership?

    You can do so with the following code:

    add_action( 'template_redirect', 'private_page', 99 );
    function private_page() {
    	if ( ! is_user_logged_in() &&  ! is_home() ) {
    		wp_redirect( wp_login_url( get_permalink() ) );
    		exit();
    	}
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    But I am just curious, is your home page and registration page same? Otherwise, above code will make the registration page private as well.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.