如何在没有任何插件的情况下创建 WordPress 自定义登录弹出模式(没有任何.弹出.自定义.插件.情况下...)

wufei123 2025-01-05 阅读:16 评论:0
登录第 1 步: 创建 cusom 登录表单短代码: // custom sign in popup form shortcod function custom_login_form() { // display the l...

如何在没有任何插件的情况下创建 wordpress 自定义登录弹出模式

登录第 1 步:
创建 cusom 登录表单短代码:

// custom sign in popup form shortcod
function custom_login_form() {

    // display the login form
    ob_start();

    ?>
    <form method="post" class="formvalidationquery login-form">
        <div class="form-group">
            <label for="">*user name</label>
            <input type="email" id="youremail" name="useremail" placeholder="email address" required />
            <span class="formerror" id="youremailerror"></span>
        </div>
        <div class="form-group">
        <label for="">*password</label>
            <input type="password" name="password" id="loginpassword" placeholder="password" required />
            <span class="formerror" id="loginpassworderror"></span>
        </div>
        <div class="d-flexinline">                    
            <input type="checkbox" id="checkbox" name="checkbox" />
            <span class="checkboxtext" id="logincheckboxtex">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</span>
        </div>
        <button type="submit" name="login" class="btn" id="login-btn">
            <span>sign in</span>
            <span class="spinner" style="display: none;"></span>
        </button>                   

    </form>
    <?php
}
add_shortcode('custom_login', 'custom_login_form');

登录第2步:
创建登录表单句柄函数:

// 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');

登录第 3 步:
在弹出模式中添加简码。

自定义注册

注册第1步:
为 cusom 注册表单简码创建函数:

// custom registration form

function custom_registration_form() {

    ?>
    <form method="post" class="formvalidationqueryregister login-form">
        <div class="form-group">
            <label for="">*user name</label>
            <input type="text" id="yourname" name="username" placeholder="username" required />
        </div>
        <div class="form-group">
            <label for="">*user email</label>
            <input type="email" id="youremail" name="email" placeholder="email" required />
        </div>
        <div class="form-group">
        <label for="">*password</label>
            <input type="password" name="password" id="loginpassword" placeholder="password" required />
            <span class="formerror" id="loginpassworderror"></span>
        </div>
        <div class="d-flexinline">                    
            <input type="checkbox" id="checkbox" name="checkbox" />
            <span class="checkboxtext" id="logincheckboxtex">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</span>
        </div>
        <button type="submit" name="register" class="btn" id="login-btn">
            <span>sign in</span>
            <span class="spinner" style="display: none;"></span>
        </button>                   

    </form>
    <?php
}
add_shortcode('custom_registration', 'custom_registration_form');


注册第2步:
创建处理注册表单请求的函数:

// 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');

以上就是如何在没有任何插件的情况下创建 WordPress 自定义登录弹出模式的详细内容,更多请关注知识资源分享宝库其它相关文章!

版权声明

本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com

分享:

扫一扫在手机阅读、分享本文

发表评论
热门文章
  • 华为 Mate 70 性能重回第一梯队 iPhone 16 最后一块遮羞布被掀

    华为 Mate 70 性能重回第一梯队 iPhone 16 最后一块遮羞布被掀
    华为 mate 70 或将首发麒麟新款处理器,并将此前有博主爆料其性能跑分将突破110万,这意味着 mate 70 性能将重新夺回第一梯队。也因此,苹果 iphone 16 唯一能有一战之力的性能,也要被 mate 70 拉近不少了。 据悉,华为 Mate 70 性能会大幅提升,并且销量相比 Mate 60 预计增长40% - 50%,且备货充足。如果 iPhone 16 发售日期与 Mate 70 重合,销量很可能被瞬间抢购。 不过,iPhone 16 还有一个阵地暂时难...
  • 酷凛 ID-COOLING 推出霜界 240/360 一体水冷散热器,239/279 元

    酷凛 ID-COOLING 推出霜界 240/360 一体水冷散热器,239/279 元
    本站 5 月 16 日消息,酷凛 id-cooling 近日推出霜界 240/360 一体式水冷散热器,采用黑色无光低调设计,分别定价 239/279 元。 本站整理霜界 240/360 散热器规格如下: 酷凛宣称这两款水冷散热器搭载“自研新 V7 水泵”,采用三相六极马达和改进的铜底方案,缩短了水流路径,相较上代水泵进一步提升解热能力。 霜界 240/360 散热器的水泵为定速 2800 RPM 设计,噪声 28db (A)。 两款一体式水冷散热器采用 27mm 厚冷排,...
  • 惠普新款战 99 笔记本 5 月 20 日开售:酷睿 Ultra / 锐龙 8040,4999 元起

    惠普新款战 99 笔记本 5 月 20 日开售:酷睿 Ultra / 锐龙 8040,4999 元起
    本站 5 月 14 日消息,继上线官网后,新款惠普战 99 商用笔记本现已上架,搭载酷睿 ultra / 锐龙 8040处理器,最高可选英伟达rtx 3000 ada 独立显卡,售价 4999 元起。 战 99 锐龙版 R7-8845HS / 16GB / 1TB:4999 元 R7-8845HS / 32GB / 1TB:5299 元 R7-8845HS / RTX 4050 / 32GB / 1TB:7299 元 R7 Pro-8845HS / RTX 2000 Ada...
  • python中int函数的用法

    python中int函数的用法
    int() 函数将值转换为整数,支持多种类型(字符串、字节、浮点数),默认进制为 10。可以指定进制数范围在 2-36。int() 返回 int 类型的转换结果,丢弃小数点。例如,将字符串 "42" 转换为整数为 42,将浮点数 3.14 转换为整数为 3。 Python 中的 int() 函数 int() 函数用于将各种类型的值转换为整数。它接受任何可以解释为整数的值作为输入,包括字符串、字节、浮点数和十六进制表示。 用法 int(object, base=10) 其中...
  • python怎么调用其他文件函数

    python怎么调用其他文件函数
    在 python 中调用其他文件中的函数,有两种方式:1. 使用 import 语句导入模块,然后调用 [模块名].[函数名]();2. 使用 from ... import 语句从模块导入特定函数,然后调用 [函数名]()。 如何在 Python 中调用其他文件中的函数 在 Python 中,您可以通过以下两种方式调用其他文件中的函数: 1. 使用 import 语句 优点:简单且易于使用。 缺点:会将整个模块导入到当前作用域中,可能会导致命名空间混乱。 步骤:...