为这个问题的新手性质做好准备...
我正在尝试将通过Unbounce目标网页表单捕获的电子邮件传递给WordPress并以编程方式注册新的WordPress用户。
这是目前的设置:
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
关于我做错了什么(也许很多事情)的任何建议?
答案 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