
登录第 1 步:
创建 cusom 登录表单短代码:
// custom sign in popup form shortcodfunction custom_login_form() { // display the login form ob_start(); ?> lorem ipsum is simply dummy text of the printing and typesetting industry. lorem ipsum has been the industry's standard dummy text ever since the 1500s <?php}add_shortcode('custom_login', 'custom_login_form');
登录第2步:
创建登录表单句柄函数:
// custom sign in poup form handlefunction 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 'alert("login failed: ' . $user->get_error_message() . '");'; } else { wp_redirect(home_url()); exit; } }}add_action('init', 'handle_custom_login');
登录第 3 步:
在弹出模式中添加简码。
自定义注册
注册第1步:
为 cusom 注册表单简码创建函数:
// custom registration formfunction custom_registration_form() { ?> lorem ipsum is simply dummy text of the printing and typesetting industry. lorem ipsum has been the industry's standard dummy text ever since the 1500s <?php}add_shortcode('custom_registration', 'custom_registration_form');
注册第2步:
创建处理注册表单请求的函数:
// custom sign up form handlefunction 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 'alert("Username already exists.");'; return; } if (email_exists($email)) { echo 'alert("Email is already registered.");'; return; } // Create a new user $user_id = wp_create_user($username, $password, $email); if (is_wp_error($user_id)) { echo 'alert("Error: ' . $user_id->get_error_message() . '");'; } else { echo 'alert("Registration successful! You can now log in.");'; } }}add_action('init', 'handle_custom_signup');
以上就是如何在没有任何插件的情况下创建 WordPress 自定义登录弹出模式的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1251908.html
微信扫一扫
支付宝扫一扫