钩入comment_post 和使用wp_insert_user():
add_action(\'comment_post\',\'wpse_255850_reg_user\',10,2);
function wpse_255850_reg_user($comment_ID, $comment_approved) {
if( 1 === $comment_approved ){
$userdata = array(
\'user_login\' => sanitize_user($_POST[\'username\']),
\'user_email\' => sanitize_email($_POST[\'user_email\']),
\'user_pass\' => NULL,
\'role\' => \'subscriber\',
\'show_admin_bar_front\' => false
);
$user_id = wp_insert_user( $userdata ) ;
// On success.
if ( ! is_wp_error( $user_id ) ) {
wp_redirect( get_permalink() ); exit;
}
} //end if
} //end function
此代码中的$\\u POST值应该反映实际注释表单的值,这里的值只是泛型值。并确保彻底清理和验证用户输入。