Update
找到这个很棒的帖子
http://tommcfarlin.com/create-a-user-in-wordpress/ 这帮助我解决了这个问题。
这是针对Shopp中的一个产品,用户可以注册多个用户参加培训课程,并且每个电子邮件都需要注册为订阅者。
这是最终代码。。
<?php
add_action( \'shopp_order_success\', \'create_subscribers\' );
function create_subscribers( $Purchase ) {
foreach ( $Purchase->purchased as $purchase ) :
$i = 1;
while ( isset( $purchase->data[\'Email \'.$i] ) ) :
$email_address = $purchase->data[\'Email \'.$i];
if ( null == username_exists( $email_address ) ) :
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $email_address, $password, $email_address );
// Set the nickname
wp_update_user(
array(
\'ID\' => $user_id,
\'nickname\' => $email_address
)
);
// Set the role
$user = new WP_User( $user_id );
$user->set_role( \'subscriber\' );
// Email the user
wp_mail( $email_address, \'Welcome!\', \'Your Password: \' . $password );
endif;
$i++;
endwhile;
endforeach;
}