简体   繁体   English

如果有其他东西,那么-这种情况能持续1行吗?

[英]IF something OR something else THEN - can this condition go on 1 line?

I am tying to add conditional logic for showing a page to logged in users. 我想添加条件逻辑以显示要登录的用户的页面。 I have 2 conditions which do not allow them to see page but instead restricted content message. 我有2个条件,不允许他们看到页面,而是限制内容消息。 Only 1 has to be true 只有1必须为真

1) They are not the Author of a form 2) They do not have a custom field called "member" 1)他们不是表单的作者2)他们没有名为“ member”的自定义字段

if( $_GET['gform_post_id'] <= 0 || $user != $author ) {
//Then show restricted content message
}

The above code is working for the first condition. 上面的代码适用于第一个条件。 But I am not sure how to add the 2nd part. 但是我不确定如何添加第二部分。 I guess it would be an elseif 我想这将是一个elseif

I guess in theory I could duplicate the restricted message by doing something like this 我猜理论上我可以通过做这样的事情来复制受限消息

if( $_GET['gform_post_id'] <= 0 || $user != $author ) {
//Then show restricted content message
} elseif {
if($memberstatus == 'member'){
//Then show restricted content message
}

The reason I do not think this si good solution is my "Restricte Content" is quite large as I write a page with Divs in HTML basically. 我之所以认为此解决方案不好是因为我的“限制内容”相当大,因为我基本上是用HTML用Divs写一个页面的。 So it looks a little clumsy in the code to duplicate this twice. 因此,将代码重复两次看起来有点笨拙。

So my question is: Is there a way to write the conditions on the same line? 所以我的问题是:有没有办法在同一行上写条件?

ie

IF Condition 1 OR Condition 2 {
//Then show restricted content message
}

Thanks 谢谢

What about this? 那这个呢?

if(($_GET['gform_post_id'] <= 0 || $user != $author) || $memberstatus == 'member' ) {
    //Then show restricted content message
} 

If I understand you right, you want this : 如果我理解的正确,那么您需要这样做:

if( ($_GET['gform_post_id'] <= 0 || $user != $author) || $memberstatus == 'member' ) {
   //Then show restricted content message
}

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

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