2015-11-28 60 views

回答

1

最好的选择是为此写一个自定义的php脚本/插件,但如果你不愿意这样做,你可以依靠现有的插件。

你可以使用一个着陆页/ Comingsoon页面插件的WordPress的电子邮件支持。

这个插件,除非它们在签署将他人隐瞒你的WordPress网站。

所以,你可以做的是添加着陆页上输入一个邮件列表的电子邮件,并把他们的帐户细节一个非常有限的WordPress用户。

这将允许他们在登录后查看和访问您的网站,如果您不想允许他们访问,只需在Wordpress中删除用户或更改密码即可。

一个例子插件这样的: https://wordpress.org/plugins/ultimate-landing-page-and-coming-soon-page

编辑:

最简单的方法是在你的模板文件夹编写自定义脚本。 在您的模板文件夹“comingsoon.php”中创建一个新文件,我们将使用此文件在电子邮件提交中创建一个新用户。

在任何其他代码之前,在header.php的顶部输入以下代码。

<?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'); 
    } 
} 
?> 

上面的代码检查访问者是否登录,如果不是,它会将访问者重定向到未来模板。

如果访问者登录它会检查用户是否是创造了超过30天前如果是这样它也将用户重定向到comingsoon模板(除非用户已登录为管理员)

欧凯现在现在是时候创建你的“comesoon.php”了,下面的代码片段中的html只是一个你可以随意设计网页样式的例子。

<?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> 

未完全测试代码,所以如果它不像预期的那样工作,请告诉我!

需要注意的是,用户必须通过访问/ wp_login url来登录,您可以在您的come on onpage页面上添加指向登录页面的链接。

但是,显示wordpress后端登录表单并不好,因此您可以使用插件来设置登录页面的样式或包含可以通过Ajax登录的插件。

使用Ajax,您可以让用户从您的comesoon页面内登录,然后在登录到实际网站后重定向它们。

希望这可以帮助你:)

+0

最好的选择是为此写一个自定义的php脚本/插件。我会如何去做这件事? –

+0

@ExtremeBeginner。我花了一些时间为您编写代码的开头。检查我的编辑!没有完全测试,所以让我知道你是否遇到问题! – Lennart

+0

注意:编辑上面的代码comesoon.php有一些问题! – Lennart

0

有几个选项,这取决于你已经拥有(被你主机)

  1. 使用VPN,给他们选择使用VPN登陆,并给他们的本地IP,或让他们获得DNS您的DNS服务器,因此可以使用一个名称(使用VPN
  2. 使用用户名+密码组合来授予访问使用.htaccess文件
  3. 只授予在.htaccess文件中定义的IP访问仅在连接
+0

我正在使用Dreamhost。 –