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
The following examples demonstrate how to display content only when a member is logged in and matches specific user criteria, such as a Membership Plan ID.
The examples first verify that a member is logged in, retrieve the member's information, and then display content based on the member's subscription_id.
Example: Display Content for a Specific Membership Plan
The following example displays content only for members whose Membership Plan ID is 1.
<?php // Check whether a member is logged in if (user::isUserLogged($_COOKIE)) { // Retrieve the currently logged-in member's data $loggedInUser = getUser($_COOKIE['userid'], $w); // Display content for Membership Plan ID 1 if ($loggedInUser['subscription_id'] == 1) { ?> ENTER CONTENT FOR MEMBERSHIP PLAN ID 1 <?php } } ?>
Replace ENTER CONTENT FOR MEMBERSHIP PLAN ID 1 with the content that should be displayed to members assigned to Membership Plan ID 1.
Example: Display Different Content for Multiple Membership Plans
The following example displays different content depending on the logged-in member's Membership Plan ID.
<?php // Check whether a member is logged in if (user::isUserLogged($_COOKIE)) { // Retrieve the currently logged-in member's data $loggedInUser = getUser($_COOKIE['userid'], $w); // Membership Plan ID 1 if ($loggedInUser['subscription_id'] == 1) { ?> ENTER CONTENT FOR MEMBERSHIP PLAN ID 1 <?php } // Membership Plan ID 2 elseif ($loggedInUser['subscription_id'] == 2) { ?> ENTER CONTENT FOR MEMBERSHIP PLAN ID 2 <?php } // Membership Plan ID 3 elseif ($loggedInUser['subscription_id'] == 3) { ?> ENTER CONTENT FOR MEMBERSHIP PLAN ID 3 <?php } // All other Membership Plans else { ?> ENTER CONTENT FOR ALL OTHER MEMBERSHIP PLANS <?php } } ?>
Replace each placeholder with the content that should be displayed for the corresponding Membership Plan ID. The else block can be used to display content for members who do not match any of the specified plans.
