PHP code snippet to check when a member/user is logged in AND matches another user value (such as a membership plan ID)

Link: https://support.brilliantdirectories.com/support/solutions/articles/12000095726-php-code-snippet-to-check-when-a-member-user-is-logged-in-and-matches-another-user-value-such-as-a-m

The code snippet below will determine when members are logged into a member account AND match additional user criteria. 


In this example we check that a user is logged in AND the user matches membership plan with an ID of 1.


Example PHP showing content for logged in membership plan 1 users

<?php
// First, check if the user is logged in
if (user::isUserLogged($_COOKIE)) {

// If logged in, then fetch data of the currently logged-in user
$loggedInUser = getUser($_COOKIE['userid'], $w);

// If the user's subscription ID is 1
if ($loggedInUser['subscription_id'] == 1) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 1

<?php } ?>

Replace "ENTER TEXT FOR SUBSCRIPTION ID 1" with your desired content. This content will be displayed only when a user is logged in.


Example PHP showing content for different logged in users

<?php
// First, check if the user is logged in
if (user::isUserLogged($_COOKIE)) {

    // If logged in, then fetch data of the currently logged-in user
    $loggedInUser = getUser($_COOKIE['userid'], $w);

// If the user's subscription ID is 1
if ($loggedInUser['subscription_id'] == 1) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 1

<?php
}
// If the user's subscription ID is 2
elseif ($loggedInUser['subscription_id'] == 2) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 2

<?php
}
// If the user's subscription ID is 3
elseif ($loggedInUser['subscription_id'] == 3) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 3

<?php
}
// For all other subscription IDs
else {
?>

ENTER TEXT FOR ALL OTHER SUBSCRIPTIONS

<?php
}
}
?>