File: /mnt/data/dreamssalon-wp/wp-content/themes/dreamsalon/registerform.php
<?php
/**
* Template Name: Dreamsalon Register
* Description: Custom full-page registration page WITHOUT header/footer.
*/
if (!defined('ABSPATH'))
exit;
// Redirect to home page if user is already logged in
if (is_user_logged_in()) {
wp_safe_redirect( home_url( '/' ) );
exit;
}
// Get logo URLs
$main_logo_url = '';
$logo_dark_url = '';
if (in_array('redux-framework/redux-framework.php', apply_filters('active_plugins', get_option('active_plugins')), true)) {
$main_logo = dreamsalon_fl_framework_getoptions('logo_dark');
if (!empty($main_logo) && isset($main_logo['url'])) {
$main_logo_url = $main_logo['url'];
}
$logo_dark = dreamsalon_fl_framework_getoptions('frontend_light');
if (!empty($logo_dark) && isset($logo_dark['url'])) {
$logo_dark_url = $logo_dark['url'];
}
} else {
$main_logo_url = get_template_directory_uri() . '/assets/images/logo_default.svg';
$logo_dark_url = get_template_directory_uri() . '/assets/images/dark-logo.svg';
}
// Handle registration form submission
if (isset($_POST['dreamsalon_register_submit'])) {
$error_message = '';
// Verify nonce
if (!isset($_POST['dreamsalon_register_nonce']) || !wp_verify_nonce($_POST['dreamsalon_register_nonce'], 'dreamsalon_register_action')) {
$error_message = 'Security verification failed.';
} else {
// Sanitize inputs
$name = sanitize_text_field($_POST['name'] ?? '');
$email = sanitize_email($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
$otp = sanitize_text_field($_POST['otp'] ?? '');
$agree_terms = isset($_POST['agree_terms']);
// Get OTP enabled status
$options = get_option('dreamsalon_theme_options');
$otp_enabled = !empty($options['otp_switch']);
// Validate inputs - OTP is only required if OTP is enabled
if (empty($name) || empty($email) || empty($password)) {
$error_message = 'All fields are required.';
} elseif (!is_email($email)) {
$error_message = 'Please enter a valid email address.';
} elseif (strlen($password) < 6) {
$error_message = 'Password must be at least 6 characters long.';
} elseif (!$agree_terms) {
$error_message = 'You must agree to the Terms & Service.';
} elseif (email_exists($email)) {
$error_message = 'This email is already registered. Please login instead.';
} elseif (username_exists($email)) {
$error_message = 'This email is already registered. Please login instead.';
} elseif ($otp_enabled && empty($otp)) {
$error_message = 'OTP is required.';
} else {
// Only verify OTP if OTP is enabled
if ($otp_enabled) {
$otp_verification = verify_registration_otp($email, $otp);
if ($otp_verification !== true) {
$error_message = $otp_verification;
}
}
// If no OTP error or OTP is disabled, create user
if (empty($error_message)) {
$user_id = wp_create_user($email, $password, $email);
if (!is_wp_error($user_id)) {
// Update user display name
wp_update_user(array(
'ID' => $user_id,
'display_name' => $name,
'first_name' => $name
));
// Clean up OTP data if OTP was used
if ($otp_enabled) {
cleanup_otp_after_registration($email);
}
// Auto-login the user
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
// Redirect to home page or dashboard
wp_safe_redirect( home_url( '/' ) );
exit;
} else {
// Handle specific WordPress user creation errors
$wp_error = $user_id;
if (in_array('existing_user_email', $wp_error->get_error_codes())) {
$error_message = 'This email is already registered. Please login instead.';
} elseif (in_array('existing_user_login', $wp_error->get_error_codes())) {
$error_message = 'This email is already registered. Please login instead.';
} else {
$error_message = $wp_error->get_error_message();
}
}
}
}
}
}
// Get OTP enabled status for template
// Get OTP expiration time from theme options
$otp_expiry_minutes = !empty($options['otp_expiration_time']) ? intval($options['otp_expiration_time']) : 5;
$otp_expiry_seconds = $otp_expiry_minutes * 60;
// Get OTP resend time from theme options
$otp_resend_minutes = !empty($options['otp_resend_time']) ? intval($options['otp_resend_time']) : 3;
$otp_resend_seconds = $otp_resend_minutes * 60;
get_template_part('templates/header/header', 'none');
?>
<?php
// Enqueue the registration script
wp_enqueue_script(
'dreamsalon-registration',
get_template_directory_uri() . '/assets/js/dreamsalon-registration.js',
array('jquery'),
'1.0.0',
true
);
// Pass PHP variables to JavaScript
wp_localize_script('dreamsalon-registration', 'dreamsalonRegistration', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'otpEnabled' => $otp_enabled, // Your PHP variable
'otpExpirySeconds' => intval($otp_expiry_seconds), // Your PHP variable
'otpResendSeconds' => intval($otp_resend_seconds), // Your PHP variable
'otpNonce' => wp_create_nonce( 'otp_nonce' ),
'emailCheckNonce' => wp_create_nonce("email_check_nonce")
));
?>
<div class="bg-light">
<div class="container-fuild position-relative z-1">
<div class="w-100 overflow-hidden position-relative flex-wrap d-block vh-100">
<div class="row justify-content-center align-items-center vh-100 overflow-auto flex-wrap py-3">
<div class="col-md-8 col-lg-6 col-xl-4 mx-auto">
<div class="d-flex flex-column justify-content-lg-center p-4 p-lg-0 pb-0 flex-fill">
<div class="mx-auto mb-4 mt-4 text-center">
<a href="<?php echo esc_url(home_url('/')); ?>">
<?php if (!empty($main_logo_url)): ?>
<img src="<?php echo esc_url($main_logo_url); ?>" class="img-fluid"
alt="<?php esc_attr_e('Logo', 'dreamsalon'); ?>">
<?php else: ?>
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/logo_default.svg'); ?>"
class="img-fluid" alt="<?php esc_attr_e('Logo', 'dreamsalon'); ?>">
<?php endif; ?>
</a>
</div>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger text-center mb-4">
<?php echo esc_html($error_message); ?>
</div>
<?php endif; ?>
<form id="dreamsalon-register-form" method="post"
class="">
<?php wp_nonce_field('dreamsalon_register_action', 'dreamsalon_register_nonce'); ?>
<div class="login-item w-100">
<h4 class="text-center"><?php esc_html_e('Create Account', 'dreamsalon'); ?></h4>
<!-- Registration Fields (Visible Initially) -->
<div id="registration-fields">
<!-- Name -->
<div class="mb-3">
<label class="form-label" for="name">
<?php esc_html_e('Name', 'dreamsalon'); ?>
<span class="text-danger ms-1">*</span>
</label>
<input type="text" name="name" id="name" class="form-control form-control-lg"
placeholder="Your Name"
value="<?php echo isset($_POST['name']) ? esc_attr( wp_unslash( $_POST['name'] ) ) : ''; ?>" required>
<span id="name-error" class="error-message"></span>
</div>
<!-- Email -->
<div class="mb-3">
<label class="form-label" for="email">
<?php esc_html_e('Email', 'dreamsalon'); ?>
<span class="text-danger ms-1">*</span>
</label>
<input type="email" name="email" id="email" class="form-control form-control-lg"
placeholder="Your Email Address"
value="<?php echo isset($_POST['email']) ? esc_attr( wp_unslash( $_POST['email'] ) ) : ''; ?>" required>
<span id="email-error" class="email-error"></span>
<div id="email-check-message" class="email-check-message"></div>
</div>
<!-- Password -->
<div class="mb-3">
<label class="form-label" for="password">
<?php esc_html_e('Password', 'dreamsalon'); ?>
<span class="text-danger ms-1">*</span>
</label>
<input type="password" name="password" id="password" class="form-control form-control-lg"
placeholder="<?php esc_attr_e('Your Password', 'dreamsalon'); ?>" minlength="6" required>
<span id="password-error" class="error-message"></span>
</div>
<!-- Terms -->
<div class=" mb-0">
<div class="d-flex align-items-center form-check form-check-md mb-0">
<input class="form-check-input me-2" id="agree_terms" name="agree_terms" type="checkbox" required>
<label for="agree_terms" class="mt-0">
<?php
printf(
esc_html__('I agree with %sTerms & Service%s', 'dreamsalon'),
'<a href="' . esc_url(home_url('/terms-conditions')) . '" class="text-primary text-decoration-underline">',
'</a>'
);
?>
</label>
</div>
<span id="terms-error" class="error-message ms-2"></span>
</div>
<input type="hidden" name="dreamsalon_register_submit" value="1">
<!-- Submit Button (Hidden Initially when OTP is enabled) -->
<div class="mb-1" id="submit-section">
<?php
$button_style = $otp_enabled ? 'display: none;' : '';
?>
<button type="submit" id="register-btn" class="btn btn-lg btn-primary w-100"
style="<?php echo esc_attr($button_style); ?>">
<?php esc_html_e('Sign Up', 'dreamsalon'); ?>
</button>
</div>
<!-- Auto Submit Message (Hidden Initially) -->
<div id="auto-submit-message" class="auto-submit-message mt-2 mb-2" style="display: none;">
<i class="fas fa-spinner fa-spin me-2"></i>
<?php esc_html_e('Completing registration and logging you in...', 'dreamsalon'); ?>
</div>
<!-- Login -->
<div class="text-center mt-3">
<?php esc_html_e('Already have an account?', 'dreamsalon'); ?>
<?php
$header_login_link = dreamsalon_fl_framework_getoptions('header_login_link');
if ($header_login_link):
$login_url = get_permalink($header_login_link);
$login_text = get_the_title($header_login_link) ?: __('Sign In', 'dreamsalon');
else:
$login_url = home_url('/login');
$login_text = __('Sign In', 'dreamsalon');
endif;
?>
<a href="<?php echo esc_url($login_url); ?>" class="register-btn text-primary fw-bold">
<?php echo esc_html($login_text); ?>
</a>
</p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_template_part('templates/footer/footer', 'none'); ?>