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 Damon - January 22, 2016

Hi Zicky,

$CURRENT_USER is  only available if you are using the Website Membership plugin. To get the current logged in user details in CMS Builder without using the Website Membership plugin, add this code above your code. I'm using $CMSB_USER as an example. You can name it anything you want.

$CMSB_USER = getCurrentUserFromCMS(); 

Now if you use the showme function you will see all the current variables and data available to use and compare:

<?php showme($CMSB_USER); ?>

Hope this helps!

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 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 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/