I made a custom admin bar that is displayed only for logged in users. But I just noticed that with "is_user_logged_in()" function it works only for admins and not contributors or spectators.
The code works for contributors and spectators in specific few pages. I believe it could be because these pages have some code that checks if users are logged in. But I don't know.
Here is my PHP and HTML code:
<?php if ( is_user_logged_in() ) : ?>
<a href="<?php global $current_user; echo home_url() . '/members/' . $current_user->user_login . '/profile/'; ?>">My profile</a>
<a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e('Log out'); ?></a>
<?php else: ?>
<span>Become a member</span>
<a href="/wp-login.php">Log in</a>
<a class="cta-small" href="/register">Get invitation</a>
<?php endif; ?>
Any ideas why it doesn't work?
I use Wordpress 5.2.1 and PHP 7.2