Rumah >pembangunan bahagian belakang >tutorial php >Cara Membuat Modal Pop Timbul Log Masuk Tersuai WordPress tanpa sebarang pemalam.
log masuk Langkah-1:
Cipta kod pendek borang log masuk Cusom:
// custom sign in popup form shortcod function custom_login_form() { // Display the login form ob_start(); ?> <form method="post"> <p><strong>sign in Step-2:</strong><br> Create login form handle function:<br> </p> <pre class="brush:php;toolbar:false"> // custom sign in poup form handle function handle_custom_login() { if (isset($_POST['login'])) { $useremail = sanitize_user($_POST['useremail']); $password = sanitize_text_field($_POST['password']); $creds = array( 'user_login' => $useremail, 'user_password' => $password, 'remember' => isset($_POST['remember']), ); $user = wp_signon($creds, false); if (is_wp_error($user)) { echo '<script>alert("Login failed: ' . $user->get_error_message() . '");</script>'; } else { wp_redirect(home_url()); exit; } } } add_action('init', 'handle_custom_login');
log masuk Langkah-3:
tambah kod pendek dalam modal timbul anda.
Pendaftaran Tersuai
daftar Langkah-1:
Cipta fungsi untuk kod pendek borang Daftar Cusom:
// custom registration form function custom_registration_form() { ?> <form method="post"> <p><strong>sign up Step-2:</strong><br> Create function for handle Sign up form request:<br> </p> <pre class="brush:php;toolbar:false"> // custom sign up form handle function handle_custom_signup() { if (isset($_POST['register'])) { $username = sanitize_user($_POST['username']); $email = sanitize_email($_POST['email']); $password = sanitize_text_field($_POST['password']); // Check if the username and email already exist if (username_exists($username)) { echo '<script>alert("Username already exists.");</script>'; return; } if (email_exists($email)) { echo '<script>alert("Email is already registered.");</script>'; return; } // Create a new user $user_id = wp_create_user($username, $password, $email); if (is_wp_error($user_id)) { echo '<script>alert("Error: ' . $user_id->get_error_message() . '");</script>'; } else { echo '<script>alert("Registration successful! You can now log in.");</script>'; } } } add_action('init', 'handle_custom_signup');
Atas ialah kandungan terperinci Cara Membuat Modal Pop Timbul Log Masuk Tersuai WordPress tanpa sebarang pemalam.. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!