-1

I have a WordPress website. I would like to put it in beta or just have restricted access to a limited amount people for a short time? I was thinking I could create a system where they submit email I send them a code and they can access the site but how? How would I go about doing this?

Peter O.
  • 32,158
  • 14
  • 82
  • 96

2 Answers2

1

The best options is write a custom php script/plugin for this, but if your not willing to do this you could rely on existing plugins.

You could use a Landing page/Comingsoon page Plugin for wordpress that has email support.

This plugin will hide your Wordpress site from anyone unless they are signed in.

So what you could do is add the emails that are entered on the Landing page to a mailing list and send them the account details of a very limited Wordpress user.

This will allow them to view and visit your site after they log in, if you don't want to allow them access just delete the user in Wordpress or change the password.

An example plugin like this: https://wordpress.org/plugins/ultimate-landing-page-and-coming-soon-page

EDIT:

The easiest way is to write a custom script in your template folder. Create a new file in your template folder "comingsoon.php", We are going to use this file to create a new user on email submit.

Enter the following code at the top of your header.php before any other code.

<?php
if ( !is_user_logged_in() ) {
    get_template_part( 'comingsoon' );
    die();
} else{
    //Check if the user has been registerd longer than 30 days if so redirect him to the comingsoonpage again
    get_currentuserinfo(); 
    $user_data = get_userdata($user_ID);
    $registered_date = $user_data->user_registered;
    if (strtotime($registered_date) <= strtotime('-30 days') && !current_user_can('administrator')){
       get_template_part( 'comingsoon' );
    }
}
?>

The code above checks if the visitor is logged in if not it will redirect the visitor to the comingsoon template.

If the visitor is logged in it will check if the user was created more than 30days ago if so it will also redirect the user to the comingsoon template(unless the user is signed in as admin)

Okey now it's time to Create your "comingsoon.php" the html in the snippet below is just an example you could style the page anyway you like.

<?php
    global $wpdb;

    $table_name = $wpdb->prefix."comingsoon_users";

    //Check if our custom DBTable exists if not create it.
    if ($wpdb->get_var('SHOW TABLES LIKE '.$table_name) != $table_name) {

      $charset_collate = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE $table_name (
          user mediumint(9) NOT NULL AUTO_INCREMENT,
          email tinytext NOT NULL,
          UNIQUE KEY user (user)
        ) $charset_collate;";

        require_once(ABSPATH.'wp-admin/includes/upgrade.php');
        dbDelta($sql);
    }

    //IF Email is submitted we will add the user to our custom DB table and retrieve the usersnumber.
    //We will use the usernumber to create an actual Wordpress user.
    if ($_POST['email']){

        $user_email = $_POST['email'];

        $userresult = $wpdb->get_results( "SELECT user FROM $table_name ORDER BY user DESC LIMIT 1");

    foreach ($userresult as $result) {            
        $usernum = $result->user;
    }

        $wpdb->insert( 
          $table_name, 
          array( 
            'user' => '',
            'email' => $user_email
          ), 
          array( 
            '%d',
            '%s'
          ) 
        );

        $usernum++;
        $user_name = 'User'.$usernum;

        //Create Wordpress user with name like: User10 and a random password.
        $user_id = username_exists( $user_name );
        if ( !$user_id and email_exists($user_email) == false ) {
            $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
            $user_id = wp_create_user( $user_name, $random_password, $user_email );
        } else {
            $random_password = __('User already exists.  Password inherited.');
        }
    }

?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>

<head>

    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="<?php bloginfo('description'); ?>">
    <meta name="author" content="WebVerder">

    <title><?php bloginfo('name'); ?></title>

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/inc/css/bootstrap.min.css" type="text/css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/inc/css/proverder.css" type="text/css">

</head>

<body id="page-top">

    <header>
        <div class="header-content">
            <div class="header-content-inner">
                <h1>Theme in development!</h1>
                <h2 class="header">Enter your email below to get a preview account.</h2>
                <hr>
                <form method="POST">
                    <div class="form-group" style="max-width: 500px; margin: 0 auto 0;">
                        <input type="email" class="form-control" name="email" placeholder="Pleace enter your Email!"><input type="submit">
                    </div>
                </form>                
            </div>
        </div>
    </header>

</body>

</html>

Haven't fully tested the code so if it's not working like expected let me know!

Something to keep in mind, the user has to login by going to the /wp_login url you could add a link to the login page on your comingsoonpage.

But it's not nice to show a wordpress backend login form so you could use a plugin to either style the login page or include a plugin that makes it possible to login through Ajax.

Using Ajax you could let a user login from within your comingsoon page and then redirect them after login to the actual website.

Hope this helps you out :)

Lennart
  • 639
  • 4
  • 14
  • The best options is write a custom php script/plugin for this. How would I go about doing this? – ExtremeBeginner. Nov 28 '15 at 18:28
  • @ExtremeBeginner. I took some time to write the beginning of the code for you. Check my edit above! Didn't test it completely so let me know if you run into problems ! – Lennart Nov 28 '15 at 23:10
  • Note: Edited the code above comingsoon.php had some issues in it! – Lennart Nov 28 '15 at 23:40
0

there are several options, depending on what you already have (were are you hosting)

  1. use vpn, give them the option to login using vpn and give them the local ip or let them get dns from your dns server so the can use a name (only when connected using vpn
  2. use a username + password combination to grant access using .htaccess file
  3. only grant access from ip defined in the .htaccess file
davejal
  • 6,009
  • 10
  • 39
  • 82