1

I am using Wordpress and it has code like this:

<?php  
    if (is_user_logged_in())   {   
?>

I want to add to it another set of if statements that check for a variable. I don't know the correct syntax but in plain English I want to say, "if users are logged in and $string1 or $string2 is empty…"

Please assist.

4 Answers 4

7
  if ( is_user_logged_in() && (empty($string1) || empty($string2)) ) {

if you need only one string to be empty but not both. use

  if ( is_user_logged_in() && (empty($string1) ^ empty($string2)) ) {
Sign up to request clarification or add additional context in comments.

1 Comment

I dont even know what the heck the ^ does in PHP. Please explain. Is that xor?
1
if (user_is_logged_in() AND (strlen($str1) == 0 OR strlen($str2) == 0))

I will note that this will work if BOTH str1 and str2 have a zero length. If the variables may not be set, as opposed to having zero length use isset instead of strlen() == 0.

Comments

1
if (user_logged_in() && (empty($string1) || empty($string2))

This requires the user_logged_in() call to return true. At least one of $string1 or $string2 needs to be empty.

Comments

1

<?php if(is_user_logged_in() && (empty($string1) || empty($string2))) ?>

Good luck :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.