Reputation: 2290
I have the code below and it results as true
with the or
or ||
logical operators. I remove the second condition and it works as expected. What am I doing wrong here?
$user = trim(get_user_role());
if ($user != 'administrator' or $user != 'editor'){
echo '<script type="text/javascript">';
echo 'jQuery(".nav > li").eq(2).hide();';
echo 'jQuery(".nav > li").eq(3).hide();';
echo '</script>';
}
I even echo
the user and it is administrator, so I know that part is right.
Upvotes: 1
Views: 36
Reputation: 78994
You are stating IF $user IS NOT administrator OR $user IS NOT editor. So if $user
is not administrator it is true
and if $user
is not editor it is true
, either one.
You want to use AND &&
:
if ($user != 'administrator' && $user != 'editor'){
Upvotes: 3
Reputation: 29278
Well, think about it.
if($user != 'administrator'... -> False->($user = 'administrator')->Check next condition.
|| $user != 'editor' -> True->($user = 'administrator)->execute.
You need to use &&
here.
Upvotes: 2