php - 在 woocommerce 中注册并重定向到登录页面时防止自动登录?

标签 php wordpress authentication woocommerce

我正在用 woo commerce wordpress 设计一个网站,我引用 this solution 将登录和注册页面分开了。

如何在没有登录的情况下在成功注册后将注册页面重定向到登录页面。用户需要使用电子邮件中的用户名和密码登录。

我的登录页面是

www.example.com/my-account/

注册页面是

www.example.com/my-account/?action=register

最佳答案

经过大量搜索,我找到了解决方案

第一步:添加WP Approve User

第二步:将这些代码添加到你的主题功能文件中

/* Stop auto login */


function user_autologout(){
       if ( is_user_logged_in() ) {
                $current_user = wp_get_current_user();
                $user_id = $current_user->ID;
                $approved_status = get_user_meta($user_id, 'wp-approve-user', true);
                //if the user hasn't been approved yet by WP Approve User plugin, destroy the cookie to kill the session and log them out
        if ( $approved_status == 1 ){
            return $redirect_url;
        }
                else{
            wp_logout();
                        return get_permalink(woocommerce_get_page_id('myaccount')) . "?approved=false";
                }
        }
}
add_action('woocommerce_registration_redirect', 'user_autologout', 2);
function registration_message(){
        $not_approved_message = '<p class="registration">Send in your registration application today!<br /> NOTE: Your account will be held for moderation and you will be unable to login until it is approved.</p>';
        if( isset($_REQUEST['approved']) ){
                $approved = $_REQUEST['approved'];
                if ($approved == 'false')  echo '<p class="registration successful">Registration successful! You will be notified upon approval of your account.</p>';
                else echo $not_approved_message;
        }
        else echo $not_approved_message;
}
add_action('woocommerce_before_customer_login_form', 'registration_message', 2);

关于php - 在 woocommerce 中注册并重定向到登录页面时防止自动登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24379214/

相关文章:

php - 如何在php中获取目录中的最新文件

php - 像 facebook 在墙贴中那样向下滚动时加载内容

authentication - 在 OAuth 2.0 中的 2-legged Authentication 中 client_id 和 client_secret 的用途是什么

jquery - 联系表单的 2 列布局的 CSS 问题

ruby-on-rails - 如何在 Devise 中实现安全的主密码/ super 密码身份验证?

php - Mysql用户验证不起作用

php - MySql:如何从表中删除具有特定 ID 的行除外的行

php - 按收藏夹表对 MySQL 表行进行排序

html - Contact Form 7 在第一次提交时不起作用,但在第二次按下 sumbit 按钮时它工作正常

mysql - 将数据库导入mysql导致表中出现0行