Jump to content
  • 0

Chek if user is logged from Wordpress


vidierre

Question

I have embedded my app with CASPIO authentication into a Wordpress site and app's users do not need to authenticate themselves on Wordprees.

Now I would like to know if a user is logged in to the app in order to show/hide some wordpress menu items. Can I check In a caspio datapage some fiedl before login? i.e. if System Parameter User Agent is Null user is not yet logged...

Anyone has been faced with this? 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 1

Hi, what would I suggest to to create a login stand alone login page if you don't have one yet (documentation), and you can also redirect each user to a different page depending on their role (documentation)

Then on the HTML page where your stand alone login page add this php script ( I think, you will need to install a plugin to run php on wordpress) . Then on you can use use PHP session.

To make it simpler, you can also just add a variable then pass it as a query string on your redirection script ( The example below is using the specific redirection code)

<script>
var today =new Date();
var signup = new Date( "[@authfield:Last_Payment]" );
var valid = new Date();
valid.setDate(today.getDate()-30);
if (valid<signup)
{
/*Valid*/
var UserLoggedIn
document.location = "http://www.mysite.com/menu.html?UserLoggedIn=1";
}
else
{
/*Not Valid*/
window.location = "http://www.mysite.com/login.html"
}
</script>

 

Then on your menu site, just get the value of the "UserLoggedIn" variable in the query string, then you can use it to show / hide anything you want using if else statements.
You can fetch this value either on your caspio datapage, but to hide the menu on your website you can also fetch this using custom coding on your wordpress page.

Link to comment
Share on other sites

  • 0
11 hours ago, innov2e said:

@PullStackDev it seems a good solution and yor answer lead me to another similar way to reach the goal:

Into the autentication configuration i set the login redirection parameter (my URL_LoginSuccess) to https:/mysite.com/?UserLoggedIn=1

the from wordpress I handle this parameter

Screenshot-2021-09-21-at-09.20.43-e16322

I see, I'm happy to know that my suggestions have help you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...