1

i'm a young informatic engineer student who is developing his first wordpress website. It is a booking website when a client can see the available hours in certain local and book it, and the local can login with his account to check the books that he has and make new ones (for example, the ones booked by phone). What i want is to display different content depending on the account which is logged in. For example, the local can see and modify all the schedule, but the client can only see the available hours and book it. I dont know if it is possible, or if it is so difficult, so i would love any help or advice. Thank you guys.

3
  • A quick tip for getting great answers: Consider starting by expanding on the summary you put in the title. Explain how you encountered the problem and any difficulties in solving it yourself. The first paragraph is the second thing most readers will see, so make it a good one. Check our guide to asking good questions if you need to. Jun 1 '20 at 19:05
  • This is a fairly broad question - more specific ones tend to get more responses. Are you wanting people to log in and manage all this on the back end, or trying to keep it all on the front end? There may already be plugins available that can do what you're needing, it may just take some research and experimenting. You could also build your own theme if you're wanting everything managed on the front end, and use simple conditionals checking the current user's capabilities.
    – WebElaine
    Jun 1 '20 at 19:06
  • It's not that broad. Surely the answer is just to check capabilities? Jun 1 '20 at 19:13
0

You are going to want to look at a few things. First, the WP_user object which will enable you to check if the user is even logged in. But you can also check capabilities with the has_cap method.

You can even define your own capabilities and apply them to users.

Then you would do something along these lines:

 <?php

 $user = wp_get_current_user();
 if($user->exists()){
      // logged in user
     if( $user->has_cap('edit_users') ){
          // user can edit users
     }else{
          // this user cannot do that
     }
 }else{
     // anon user
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.