Skip to content

Instantly share code, notes, and snippets.

@VelichkoAlexander
Created August 18, 2018 09:25
Show Gist options
  • Save VelichkoAlexander/984d991ab8e3f38b623c8744a3cbd303 to your computer and use it in GitHub Desktop.
Save VelichkoAlexander/984d991ab8e3f38b623c8744a3cbd303 to your computer and use it in GitHub Desktop.
Custom registration
<?php
$err = '';
$success = '';
global $wpdb, $PasswordHash, $current_user, $user_ID;
if (isset($_POST['task']) && $_POST['task'] == 'register') {
$first_name = $wpdb->escape(trim($_POST['first_name']));
$last_name = $wpdb->escape(trim($_POST['last_name']));
$email = $wpdb->escape(trim($_POST['email']));
$pwd1 = $wpdb->escape(trim($_POST['pwd1']));
$middle_name = $wpdb->escape(trim($_POST['middle_name']));
$scientific_research = $wpdb->escape(trim($_POST['scientific_research']));
$specialty = $wpdb->escape(trim($_POST['specialty']));
$city = $wpdb->escape(trim($_POST['city']));
// $username = $wpdb->escape(trim($_POST['username']));
if ($email == "" || $pwd1 == "" || $first_name == "" || $last_name == "") {
$err = 'Please don\'t leave the required fields.';
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$err = 'Invalid email address.';
} else if (email_exists($email)) {
$err = 'Email already exist.';
} else {
$user_id = wp_insert_user(array('first_name' => apply_filters('pre_user_first_name', $first_name), 'last_name' => apply_filters('pre_user_last_name', $last_name), 'user_pass' => apply_filters('pre_user_user_pass', $pwd1), 'user_login' => apply_filters('pre_user_user_email', $email), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'subscriber'));
if (is_wp_error($user_id)) {
$err = 'Error on user creation.';
die($err);
} else {
update_field('middle_name', $middle_name, 'user_' . $user_id);
update_field('scientific_research', $scientific_research, 'user_' . $user_id);
update_field('specialty', $specialty, 'user_' . $user_id);
update_field('city', $city, 'user_' . $user_id);
do_action('user_register', 'user_' . $user_id);
$success = 'You\'re successfully register';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment