我目前正在使用此处的一些代码编写前端表单-orginal
add_action(\'template_redirect\', \'register_a_user\');
function register_a_user(){
if(isset($_GET[\'do\']) && $_GET[\'do\'] == \'register\'):
$errors = array();
if(empty($_POST[\'user\']) || empty($_POST[\'email\'])) $errors[] = \'provide a user and email\';
if(empty($_POST[\'first_name\']) || empty($_POST[\'last_name\'])) $errors[] = \'provide name\';
if(!empty($_POST[\'spam\'])) $errors[] = \'gtfo spammer\';
if(!empty($_POST[\'pass1\']) && !empty($_POST[\'pass2\'])) $error[] = \'The passwords you entered do not match\';
$account = esc_attr($_POST[\'account_type\']);
$user_login = esc_attr($_POST[\'user\']);
$user_email = esc_attr($_POST[\'email\']);
$user_pass = esc_attr($_POST[\'pass1\']);
$user_pass2 = esc_attr($_POST[\'pass2\']);
$user_first = esc_attr($_POST[\'first_name\']);
$user_last = esc_attr($_POST[\'last_name\']);
$b_email = esc_attr($_POST[\'broker_email\']);
wp_update_user( array( \'ID\' => $current_user->ID, \'broker_email\' => esc_url( $_POST[\'broker_email\'] ) ) );
require_once(ABSPATH.WPINC.\'/registration.php\');
$sanitized_user_login = sanitize_user($user_login);
$user_email = apply_filters(\'user_registration_email\', $user_email);
if(!is_email($user_email)) $errors[] = \'invalid e-mail\';
elseif(email_exists($user_email)) $errors[] = \'this email is already registered\';
if(empty($sanitized_user_login) || !validate_username($user_login)) $errors[] = \'invalid user name\';
elseif(username_exists($sanitized_user_login)) $errors[] = \'user name already exists\';
if(empty($errors)):
if ( $_POST[\'pass1\'] == $_POST[\'pass2\'] ) {
$user_data = array (
\'user_login\' => $sanitized_user_login,
\'user_pass\' => $user_pass,
\'user_email\' => $user_email,
\'user_first\' => $user_first,
\'user_last\' => $user_last,
\'b_email\' => $b_email,
\'role\' => $account
);
// Create the user
$user_id = wp_insert_user( $user_data );
} else {
$errors[] = \'passwords dont match\';
}
if(!$user_id):
$errors[] = \'registration failed...\';
else:
wp_new_user_notification($user_id);
endif;
endif;
if(!empty($errors)) define(\'REGISTRATION_ERROR\', serialize($errors));
else define(\'REGISTERED_A_USER\', $user_email);
endif;
}
在我的注册表中,我尝试添加这3个字段<input type="text" name="broker_email" class="form-control" value="" />
<input type="text" name="first_name" class="form-control" value="" />
<input type="text" name="last_name" class="form-control" value="" />
除了名称字段未保存和“broker email”字段未保存外,所有内容几乎都正常工作。我做错了什么?