通过Unbounce表单注册WordPress用户

时间:2014-12-12 19:18:37

标签: php wordpress user-registration

为这个问题的新手性质做好准备...

我正在尝试将通过Unbounce目标网页表单捕获的电子邮件传递给WordPress并以编程方式注册新的WordPress用户。

这是目前的设置:

  1. Unbounce登陆页面(get.slideheroes.com/testing)
  2. 通过将表单数据发布到网址
  3. 来传递电子邮件地址
  4. 目标网址为https://www.slideheroes.com/newuser.php
  5. PHP(在newuser.php中)代码如下:

    if( null == username_exists( $email ) ) {
    
      // Generate the password and create the user
      $password = wp_generate_password( 12, false );
      $user_id = wp_create_user( $email, $password, $email );
    
      // Set the nickname
      wp_update_user(
        array(
          'ID'          =>    $user_id,
          'nickname'    =>    'Trial User'
        )
      );
    
      // Set the role
      $user = new WP_User( $user_id );
      $user->set_role( 'contributor' );
    
      // Email the user
      wp_mail( $email, 'Welcome!', 'Your Password: ' . $password );
    
    } // end if
    
  6. 关于我做错了什么(也许很多事情)的任何建议?

1 个答案:

答案 0 :(得分:0)

为了使其正常工作,您必须包含wp-load.php并将$ email变量设置为已发布的值:

require_once('/path/to/wp-load.php');

$email = $_POST['email']; // maybe some extra validation if needed

if( null == username_exists( $email ) ) {

  // Generate the password and create the user
  $password = wp_generate_password( 12, false );
  $user_id = wp_create_user( $email, $password, $email );

  // Set the nickname
  wp_update_user(
    array(
      'ID'          =>    $user_id,
      'nickname'    =>    'Trial User'
    )
  );

  // Set the role
  $user = new WP_User( $user_id );
  $user->set_role( 'contributor' );

  // Email the user
  wp_mail( $email, 'Welcome!', 'Your Password: ' . $password );

} // end if