Displaying content to Admin, Editors and Authors on the front-end of site.

6 posts by 2 authors in: Forums > CMS Builder
Last Post: January 27, 2016   (RSS)

By Mikey - January 21, 2016

I need to display content on a site page only to site admin(s) and editor(s)... I've tried a few scenarios but I'm just not getting it.

Here's basically what I'm trying to do... but this code does not work.

<?php if($CURRENT_USER['isAdmin']) : ?> 
Display Admin Message / Content
<?php endif; ?>

<?php if($CURRENT_USER['accessLevel'] == 9 ) : ?> 
Display Editor Message / Content
<?php endif; ?>

<?php if($CURRENT_USER['accessLevel'] == 6 ) : ?> 
Display Author Message / Content
<?php endif; ?>

Anyone have any suggestions? Thanks, Zicky

By Mikey - January 22, 2016

Hey Damon,

Thanks for the code snippet... very useful.

I think I may not have explained myself well enough, or I'm not understanding something in your reply.

So what I'm trying to do is figure out the php code to display on a webpage - content based on the site manger's permissions.

So an Admin would see one  type of Message / Content
An Editor would see another type of Message / Content
And an Author would see another type of Message / Content

all based on their "accounts" permissions.

Thanks, Zicky

By Damon - January 22, 2016 - edited: January 22, 2016

HI Zicky,

Try this code:

<?php $CMSB = getCurrentUserFromCMS(); ?>

<?php if($CMSB): //if there is a user, do this. No user, then no error message ?>

<?php foreach ($CMSB['accessList'] as $record): ?>
    <?php $accessLevel = $record['accessLevel']; ?>
<?php endforeach; ?>

<?php if($CMSB['isAdmin']) : ?> 
  Display Admin Message / Content <br />
<?php endif; ?>

<?php if($accessLevel == 9 ) : ?> 
  Display Editor Message / Content <br />
<?php endif; ?>

<?php if($accessLevel == 6 ) : ?> 
  Display Author Message / Content <br />
<?php endif; ?>

<?php endif; ?>

After testing this out, it displayed both the Admin message and Editor message which makes sense as most Admins are also Editors. Also, I wrapped most of the code in an IF statement so that it will only run if a user exists and also prevent error message when user doesn't exist.

Let me know if this works for you and if you have any questions about it.

Thanks!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Mikey - January 27, 2016

Hey Damon,

Thanks for the help. Does the trick!

By chance is there any way to perform a function "By Section" permissions?  OR if there's a better way to do this. Basically I would like to display content on a page based on the user's "By Section" permissions to access specific section editors and their perspective site pages.  The code below wouldn't work, but hopefully you'll get were I'm going with this. 

<?php if($accessLevel == by section ) : ?>
   Display Author Message / Content <br />
<?php endif; ?>

Thanks Zick

By Damon - January 27, 2016

Hi Zicky,

Check out the code Jerry and I worked on together to create a page that displays all the user access by table (by section) and the access level for each:

http://www.interactivetools.com/forum/forum-posts.php?postNum=2237472#post2237472

Not exactly what you are after but you could repurpose the code.

Let me know what you think.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/