2012-03-20 94 views
0

我試圖將wordpress註冊嵌入到主頁中。我已經創建了一個自定義註冊頁面,問題在於它調用了頁眉信息,當我將它包含在php include中時,我得到這個錯誤。將wordpress註冊嵌入主頁

警告:不能更改頭信息 - 頭已經發出已

有沒有一種方法,我可以用我的代碼,但它改變它在某種程度上/工作在某種程度上,這樣的登記表被完全嵌入/頁面工程使用ajax,但它的工作原理。我不是輝煌的用PHP所以請原諒,如果這是一個愚蠢的問題:

電流寄存器代碼(在自己的網頁作品,但不包括在主頁模板時)

<?php 
require_once(ABSPATH . WPINC . '/registration.php'); 
global $wpdb, $user_ID; 
//Check whether the user is already logged in 
if (!$user_ID) { 

     if($_POST){ 
      //We shall SQL escape all inputs 
      $username = $wpdb->escape($_POST['username']); 
      if(empty($username)) { 
       echo "User name should not be empty."; 
       exit(); 
      } 
      $email = $wpdb->escape($_POST['email']); 
      if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) { 
       echo "Please enter a valid email."; 
       exit(); 
      }  

       $random_password = wp_generate_password(12, false); 
       $status = wp_create_user($username, $random_password, $email); 
       if (is_wp_error($status)) 
        echo "Username already exists. Please try another one."; 
       else { 
        $from = get_option('admin_email'); 
        $headers = 'From: '.$from . "\r\n"; 
        $subject = "Registration successful"; 
        $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password"; 
        wp_mail($email, $subject, $msg, $headers); 

        echo "Please check your email for login details."; 
       } 

      exit(); 

     } else { 
      echo "";   
      ?> 

      <!-- <script src="http://code.jquery.com/jquery-1.4.4.js"></script> --> <!-- Remove the comments if you are not using jQuery already in your theme --> 


      <?php     
      if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator 
      ?> 

      <h1><?php the_title(); ?></h1> 
      <br /><br /> 
      <div id="result"></div> <!-- To hold validation results --> 
      <form id="wp_signup_form" action="" method="post"> 

      <label><p>Username:</p></label> 
      <input type="text" name="username" class="text" value="" /> 
      <br /><br /> 
      <label><p>Email address:</p></label> 
      <input type="text" name="email" class="text" value="" /> <br /> 
      <br /> 
      <input type="submit" id="submitbtn" class="Buttons" name="submit" value="Register" /> 
      <br /> 
      <br /> 
      </form> 

      <script type="text/javascript">       
      $("#submitbtn").click(function() { 

      $('#result').html('<img src="<?php bloginfo('template_url'); ?>/images/loader.gif" class="loader" />').fadeIn(); 
      var input_data = $('#wp_signup_form').serialize(); 
      $.ajax({ 
      type: "POST", 
      url: "<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>", 
      data: input_data, 
      success: function(msg){ 
      $('.loader').remove(); 
      $('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow'); 
      } 
      }); 
      return false; 

      }); 
      </script> 

      <?php 
       } 

      else echo "Registration is currently disabled. Please try again later."; 
      ?> 

      </div> 
      </div> 
      <?php 

      echo ""; 
     } //end of if($_post) 

} 
else { 
    wp_redirect(home_url()); exit; 
} 
?> 

回答

0

正如webfan所示,在主頁上重新生成註冊功能並不是一個好主意。從登記頁面簡單地剪切和粘貼登錄表單並將action指向註冊頁面:

<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>"> 
    <!-- registration form HTML goes here --> 
</form>