I am trying to create function for Wordpress which will...
Scenario 1 is this post in Art Artist category...oh yes it is...than continue if... is this user checking the post from Art Artist category an Contributor...oh yes he/she is...continue... show him or her art_artist shortcode content
Scenario 2 is this post in Art Artist category...oh yes it is...than continue if... is this user checking the post from Art Artist category an Contributor...oh no he/she is not...show him or her this... No bro!
Scenario 3 is this post in Art Artist category...oh no it is not...than continue whatever...
Something like this...
<?php
$user = wp_get_current_user();
if ((in_category('Art Artist')) && in_array('contributor', (array)$user->roles))
{
echo do_shortcode('[art_artist]');
}
elseif ('is category art artist but is not contributor')
{
echo 'No bro!';
}
else
{
echo do_shortcode('[art_artist]');
};
?>
You were pretty much already there.
Your logic needed is within the first if condtional, all you need is !
prefixed before the in_array
.
!
- means (in this context): if condition is NOT met. So you're if/elseif should look like:
if ((in_category('Art Artist')) && in_array('contributor', (array)$user->roles)) {
echo do_shortcode('[art_artist]');
} elseif ((in_category('Art Artist')) && !in_array('contributor', (array)$user->roles)) {
echo 'No bro!';
}