Display message once per session to users with a specific role

I need to display a message to only users with a specific role. The message should appear either as soon as the user logs in or if they re-open their browser after having closed it when logged in to the site.

Can someone point me in the right direction as to how to go about accomplishing this? Would it be best to use PHP’s sessions, HTML5’s web storage or cookies in JavaScript or PHP?

1 Answer
1

You can check whether this plugin helps you to achieve your purpose
or
You can write your own code in your custom plugin with the following approach:

  • Check if the user is logged in.
  • Check if the current user has the any roles from the specified list of roles which you want the notice to be shown.
  • If the above conditions are true just add a Notice to the site.

You might not be needing sessions as you check whether the user is logged in an show the message. If at all you need WordPress Sessions you can use the functions defined in the class WP_Session_Tokens.

Leave a Comment