// ----------------------------
// User Registration & Login with Mobile (Persian + Jalali)
// ----------------------------
add_shortcode('csc_user_login_register', function() {
if (is_user_logged_in()) {
return '
شما وارد شده اید. خروج
';
}
$output = '';
$errors = [];
// Handle form submission
if (isset($_POST['csc_register'])) {
$mobile = sanitize_text_field($_POST['mobile']);
$password = sanitize_text_field($_POST['password']);
if (!preg_match('/^09\d{9}$/', $mobile)) {
$errors[] = 'شماره موبایل صحیح نیست.';
}
if (empty($password)) {
$errors[] = 'رمز عبور را وارد کنید.';
}
if (empty($errors)) {
// Check if user exists
if (username_exists($mobile)) {
$errors[] = 'این شماره موبایل قبلاً ثبت شده است.';
} else {
// Create user with mobile as username
$user_id = wp_create_user($mobile, $password, $mobile.'@example.com');
if ($user_id) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
wp_redirect(get_permalink()); // Reload page
exit;
} else {
$errors[] = 'خطا در ایجاد حساب کاربری.';
}
}
}
}
// Handle login
if (isset($_POST['csc_login'])) {
$mobile = sanitize_text_field($_POST['mobile']);
$password = sanitize_text_field($_POST['password']);
$user = wp_authenticate($mobile, $password);
if (is_wp_error($user)) {
$errors[] = 'شماره موبایل یا رمز عبور اشتباه است.';
} else {
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
wp_redirect(get_permalink()); // Reload page
exit;
}
}
// Show errors
if (!empty($errors)) {
foreach ($errors as $err) {
$output .= ''.$err.'
';
}
}
// Registration form
$output .= '
ثبت نام مشتری
';
// Login form
$output .= '
ورود مشتری
';
return $output;
});
بایگانیهای آرتین - پخش روغن و فیلتر
پرش به محتوا