Redwall
Redwall

Reputation: 1020

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. Only 1 has to be true

1) They are not the Author of a form 2) They do not have a custom field called "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

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. 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?

i.e.

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

Thanks

Upvotes: 0

Views: 2362

Answers (2)

If I understand you right, you want this :

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

Upvotes: 2

Louis Huppenbauer
Louis Huppenbauer

Reputation: 3714

What about this?

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

Upvotes: 4

Related Questions