Check if user is logged in and what permissions they have

I am trying to create a custom navigation menu that changes depending on whether or not the user is logged in. I would also like to add links in the navigation to the admin panel etc. if the user has permission to use them.

Is there a function or easy method of testing whether the user is logged in and what permissions their account has?

Comments

  • fretzl Administrator, Developer
    You can check if a user is logged in like this:
    `
    if ( zp_loggedin() ) {
    do something...
    }
    `
    You can also check if a user is logged in with, for example, upload rights like this:
    `
    if ( zp_loggedin(UPLOAD_RIGHTS) ) {
    do something...
    }
    `
    You'll find rights definitions on this page http://www.zenphoto.org/news/an-overview-of-zenphoto-users
    They are constants (i.e. OVERVIEW_RIGHTS, USER_RIGHTS, etc)

    I would also like to add links in the navigation to the admin panel etc. if the user has permission to use them.

    Not sure what you mean exactly. Can you describe an example ?
  • I'm going to hide the default #zp__admin_module and instead have some of the links in my custom navigation which changes depending on user rights. There will also be some buttons on the image/album pages that will change as well.

    I think the link you provided has all of the information I need, thank-you very much for taking the time to answer.

    One last question. Is there a way to get and display the user's name? I would like to have the user's name printed (if supplied) as the text for the user page link.
  • acrylian Administrator, Developer
    If you mean the "admin toolbox" on the top right (which btw shows the user name) there a are filter hooks available to add custom links. There are also some to add tabs on the backend via plugins. Info about those and more here:
    http://www.zenphoto.org/news/zenphoto-plugin-architecture

    A (rather complex) plugin doing these things is the Zenpage CMS plugin for example.

    You can access user values via the Zenphoto_Administrator class:
    http://www.zenphoto.org/news/zenphotos-object-model-framework
Sign In or Register to comment.