简体   繁体   English

重力表格用户注册-禁用登录用户。

[英]Gravity Forms User Registration - disable for logged-in users.

I'm trying to modify the below code snippet / function hook to disable registration if the user is logged in. 我正在尝试修改以下代码片段/功能挂钩,以在用户登录后禁用注册。

<?php
add_filter("gform_disable_registration", "disable_registration", 10, 4);
function disable_registration($is_disabled, $form, $entry, $fulfilled){
//check form id and if not the form being checked status passed in to function
if ($form["id"] != 160)
    return $is_disabled;

//check submitted values to decide if registration should be stopped
if ($entry["4"] == "No" && $entry["5"] == "No") {
    //disable registration
    return true;
}
else{
    return false;
}   
}
?>

I've tried the following to no avail: 我尝试了以下无济于事:

add_filter("gform_disable_registration", "disable_registration", 10, 4);
function disable_registration($is_disabled, $form, $fulfilled){
//check form id and if not the form being checked status passed in to function
if ($form["id"] != 2)           
return $is_disabled;
 //check user login to decide if registration should be stopped
   if( ! is_user_logged_in() ) {
return true;        
}
else {
return false;
}  
}

Hoping I can get this to work! 希望我能做到这一点! Thank you. 谢谢。

Here is an article/snippet I wrote to do this... I didn't confirm if this is still the best way to accomplish this, but it certainly is a way that works. 这是我为此写的文章/摘录...我不确定这是否仍然是实现此目的的最佳方法,但肯定是可行的。 :) :)

http://gravitywiz.com/skip-user-registration-for-logged-in-users/ http://gravitywiz.com/skip-user-registration-for-logged-in-users/

I believe there's a setting in the Form Settings to allow you require users to be logged in. Is there a reason you can't just use that? 我相信“表单设置”中有一个设置,可让您要求用户登录。是否有原因不能仅使用该设置?

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM