Simple Membership Plugin › Forums › Simple Membership Plugin › PHP to check if user is logged in
- This topic has 6 replies, 3 voices, and was last updated 6 years, 4 months ago by
Denise.
-
AuthorPosts
-
March 1, 2020 at 3:55 pm #19861
Denise
ParticipantHello! I’m using PHP to check if the user is logged in that I got off of this page: https://simple-membership-plugin.com/simple-membership-miscellaneous-php-tweaks/ I’m using it to add a class to my body tag. It worked. The problem occurred when I deactivated the plugin because of another issue. The PHP code actually caused the site to go down. I’m not a big coder. Is an else statement necessary? Would that prevent the site from going down if the plugin isn’t installed? What other ways can I accomplish adding a class to the body tag if the user is logged in? It would be extremely useful if this were part of the plugin itself!
March 4, 2020 at 10:36 pm #19882mbrsolution
ModeratorHi,
I have submitted a message to the developers to investigate further your issue/question.
Thank you
March 4, 2020 at 10:54 pm #19884Denise
ParticipantAwesome! Thank you very much!
March 5, 2020 at 12:10 am #19885admin
KeymasterYou should check if the method exists. That will prevent any error from happening if the plugin is deactivated.
Below is an example snippet of code to show you how to use the method_exists function of PHP
<?php if ( method_exists('SwpmMemberUtils', 'is_member_logged_in') ) { //Now lets use that function to check if the member is logged-in if ( SwpmMemberUtils::is_member_logged_in() ) { //Member is logged-in. Do something } } ?>March 5, 2020 at 12:23 am #19886Denise
ParticipantThis is exactly what I needed! Thank you! Brilliant!
Now maybe add it to your documentation. 😉
March 5, 2020 at 12:30 am #19887admin
KeymasterGlad to hear that it helped.
That documentation is actually for developers. We only want to list the helpful functions available from our plugin. It will be upto the developer as to how they want to use it. A developer will already know how best to utilize the functions.
We don’t really want to start getting too much into implementation because different people will use it differently and then before you know it, we will have to start explaining what PHP is. That is beyond the scope of free support.
March 5, 2020 at 1:02 am #19889Denise
ParticipantWell, thank you very much for extending yourself to me for this implementation!
-
AuthorPosts
- You must be logged in to reply to this topic.