function custom_tutor_student_registration() {
if (isset($_POST[‘custom_register’])) {
$first_name = sanitize_text_field($_POST[‘first_name’]);
$last_name = sanitize_text_field($_POST[‘last_name’]);
$email = sanitize_email($_POST[’email’]);
$password = $_POST[‘password’];

// Generate a unique username based on email
$username = sanitize_user(current(explode(‘@’, $email)));

// Check if email already exists
if (email_exists($email)) {
echo „

Error: This email is already registered.

„;
return;
}

// Create the user
$user_id = wp_create_user($username, $password, $email);

if (!is_wp_error($user_id)) {
// Assign the ‘subscriber’ role (default student role)
wp_update_user([
‘ID’ => $user_id,
‘role’ => ‘subscriber’,
‘first_name’ => $first_name,
‘last_name’ => $last_name
]);

// Mark user as Tutor LMS student
update_user_meta($user_id, ‘_is_tutor_student’, true);
update_user_meta($user_id, ‘first_name’, $first_name);
update_user_meta($user_id, ‘last_name’, $last_name);

// Auto-login the new student
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);

// Redirect to the student dashboard
wp_redirect(site_url(‘/student-dashboard’)); // Change this to your actual student dashboard URL
exit;
} else {
echo „

Error: ” . $user_id->get_error_message() . „

„;
}
}
}

// Shortcode for the form
function custom_tutor_registration_shortcode() {
ob_start();
custom_tutor_student_registration(); // Process the registration

?>





<?php return ob_get_clean(); } add_shortcode(‘custom_tutor_registration’, ‘custom_tutor_registration_shortcode’);