Apr 14 2008

How to hide content from registered users and guests in Joomla 1.5

Print
Written by David Towers   
Monday, 14 April 2008

Hide content from guests When building a website with Joomla 1.5, you might need to hide content from registreted users and guests. When we were recently building a website with Joomla 1.5, we came across the 3 options:

In this post we will be discussing the pros and cons of each of these plugins and explaining how to make RokAccess work in Joomla 1.5.

Hiding content depending on whether a user is a registered member or a guest is a really useful feature to have. Fortunately, there are a number of different options available set content permissions in Joomla 1.5...

JoomiHide

How JoomiHide works

This is the simplest plugin available for Joomla 1.5 to hide content. Although it's simple it works seamlessly for showing content either to registered members or guests.

Content in an article can be restricted to be displayed to certain visitors by adding these tags:

{reg} This content is only displayed to registered users logged in {/reg}
{unreg} This content is only displayed to unregistered users or non-logged in users {/unreg}

When content is restricted for non-members, this plugin replaces the restricted text with: "To view rest of this section, please login or register". This is a nice feature but a little annoying to have it displayed each time content is not displayed. To remove or edit this text, you can hack the plugin by changing the html code on line 108 of joomihide.php which is in /plugins/content/.

Unlike content restricted for non-members, when content is not shown to registered users there is no text added.

Pros

  • Simple

Cons

  • Downloading this membership at HowIDid Academy which will set you back $10 for 3 months.
  • Content can only be hidden to members and non-members: There is no option of showing content to administrators or other Joomla groups
  • Need to hack the plugin to remove or change the text displayed when content restricted for guests

Click here to see what other people are saying about JoomiHide. Click here to download this plugin.

Ninja Access

How Ninja Access works

Hide content using this plugin by surrounding the content you want to be seen by certain groups in a tag. Ninja Access uses numbers to specify which group the content includes:

{njaccess 0} Shows this content only to guests {/njaccess}
{njaccess 18,19,20,21,23,24,25}
Shows this content to all users who are guests {/njaccess}
{njaccess 24,25,30,31}
Shows this content to administrators and 2 custom groups created in JACL {/njaccess}

When content is not shown to a particular group, the text is simply hidden.

As you can see from the examples above, you need to know the default Joomla GroupIDs: 0 - Guest, 18 - Registered, 19 - Author, 20 - Editor, 21 - Publisher, 23 - Manager, 24 - Administrator, 25 - Super Administrator.

Pros

  • Very complete plugin for hiding content for specific groups including groups created with JACL
  • Great support from the Ninjoomla team

Cons

  • You need to have the GroupIDs at hand when you use this plugin.
  • Downloading this requires Silver Membership at NinJoomla which will set you back $30.

Find out more about Ninja Access here.

RokAccess

RokAccess is an extremely popular plugin for Joomla 1.0, but hasn't yet been updated for Joomla 1.5. Thanks to Lukas White, we managed to get RokAccess working in Joomla 1.5.

How to get RokAccess working in Joomla 1.5

After installing the Joomla 1.0 RokAccess extension on your Joomla 1.5 website, you will need to change the rokaccess.php file which is located in /plugins/content/

There are 3 changes you need to make to this file:

$_MAMBOTS->registerFunction( 'onPrepareContent', 'botRokAccess' );
Change to:
$mainframe->registerEvent( 'onPrepareContent', 'botRokAccess' );
function botRokAccess( $published, &$row, &$params, $page=0 )
Change to:
function botRokAccess( &$row, &$params, $page=0 ) {
Delete:
if (!$published) {
      $row->text = preg_replace( $regex, '', $row->text );
      return;
   }

How RokAccess works

To hide content using the RokAccess plugin you add the RokAccess tag to the content you want to hide. Here are some examples:

{rokaccess guest} Shows this content only to guest users {/rokaccess}
{rokaccess !guest}
Shows this content to all users who are not a guest {/rokaccess}
{rokaccess registered}
Shows this content to all users who are registered {/rokaccess}
{rokaccess guest,!editor}
Shows this content this to all guests and members who are not editors {/rokaccess}
{rokaccess editor,special}
Shows this content to editors, administrators, and superadministrators {/rokaccess}

In similarity to Ninja Access, when content is not shown to a particular group, the text is simply hidden.

Pros

  • Free
  • Complete

Cons

  • You need to hack the plugin files to get this working in Joomla 1.5
  • No support

Click here to see what other people are saying about RokAccess. Click here to download this plugin.

Which should plugin should you choose?

It just depends on what your needs are. We recommend you choose the plugin you're comfortable using... If you don't want to hack any files and need support with getting the plugin to work, we recommend you use the Ninjoomla plugin.

Do you have any experience with these plugins? We welcome your comments below.

18 Comments
Alex A
April 15, 2008
Votes: +1

You said that RokAccess was for Joomla 1.0 - if I want to use it in Joomla 1.5 like you state do I have to have legacy mode enabled?

report abuse
vote down
vote up
GreatGatsby
April 16, 2008
Votes: +0

No, I think you just have to hack the rokaccess.php file as described in the article.

report abuse
vote down
vote up
David T
April 16, 2008
Votes: +0

You're spot on GreatGatsby, RokAccess should work without legacy mode enabled. Welcome to GoodWebPractices by the way!!!

report abuse
vote down
vote up
Mark Simpson
April 17, 2008
Votes: +0

Hi David,

Thank you for featuring Ninja Access in your article. smilies/smiley.gif

$30 is a heck of a lot to pay for Ninja Access (I wouldn't pay that myself unless it was for a well-paying client project), so I just wanted to stress again that the $30 is for membership in the club, which means you actually get dozens of professionally supported extensions for the $30.

Also, Ninja Access... like all the other extensions we provide to our members, is not proprietary and can be used on as many websites as one wishes.

Thanks again for the mention David. If this post sounds more "salesy" then informative, apologies and feel free to delete it.

Cheers

report abuse
vote down
vote up
David T
April 17, 2008
Votes: +1

Thanks for pointing that out Mark.

The Ninja Access Silver Membership gives access to lots of other extensions, but as I stated in my post the key advantage to the Ninja Access plugin is the professional support. I expect some of our readers will choose to use Ninja Access because of the support rather than the actual extension being better than the others.

report abuse
vote down
vote up
aravot
April 19, 2008
Votes: +0

For php5 change this
function botRokAccess( &$row, &$params, $page=0 ) {
to this
function botRokAccess( $row, $params, $page=0 ) {

report abuse
vote down
vote up
Salyris Studios
April 19, 2008
Votes: +0

Great article David!

I am curious if you have tried out or looked at JoomSuite J!1.5 extensions: http://joomsuite.com/

Let me know your thoughts.

report abuse
vote down
vote up
David T
April 22, 2008
Votes: +0

Thanks Aravot for that.

Salyris Studios, I haven't actually used any of your extensions yet.

Am I right in thinking your "JoomSuite Permission" extension would allow the restricting of content based upon membership? Perhaps you could tell us more about it?

report abuse
vote down
vote up
David T
May 02, 2008
Votes: +0

There is a new plugin from GreatJoomla.com which also control display of content to just the site users that you want to have see it, here is the link: http://extensions.joomla.org/c...Itemid,35/

report abuse
vote down
vote up
Salyris Studios
May 03, 2008
Votes: +0

Sorry David, the JoomSuite are not a Salyris Studios product, I was just curious if you knew much about them or used them. ;-)

report abuse
vote down
vote up
David T
May 03, 2008
Votes: +1

Ok my mistake! smilies/smiley.gif Well I haven't tried the JoomSuite extensions yet...

report abuse
vote down
vote up
Kevin
May 23, 2008
Votes: +1

Thanks for the info here. I thought I'd add some info on JoomSuite products as I've purchased four of them; JoomMember, JoomUser, JoomContent, and JoomDefender. While I think these components have potential, they are all technically still in beta. Support is just ok, so expect to wait a few days for responses. The English in all the components is atrocious, so plan on digging through the ini files. Note that all components are also encrypted, so customization is limited. This being said, JoomUser is pretty stable but does require a hack to your login mod if you don't use theirs, but I held off on buying the permissions component due to way too many bugs. I'd say visit them in August when they claim their components will be officially released.

report abuse
vote down
vote up
David T
May 23, 2008
Votes: +0

Thanks for the feedback re: JoomSuite's products Kevin! smilies/smiley.gif

report abuse
vote down
vote up
hyunkeln
June 18, 2008
Votes: +0

Does RokAccess work with 'JXtended Control' defined user groups?

Thanks!

report abuse
vote down
vote up
Andrea
July 08, 2008
Votes: +0

re: Rok Access ...

Easy, and exactly what I needed! I'm redesigning the website for the church I work at, and we need/want to keep some areas accessible to registered users (church members) only. I'm working on a photo gallery, and instead of having 2 galleries, this lets me work around and only have one, showing the restricted galleries to members.

I did have to enable legacy mode to install the plugin. After that, I just had to make those 3 changes, and Bob's your uncle!

I had to leave legacy mode enabled to avoid this error message ...

"Direct Access to this location is not allowed."

... Not a big deal, and with my luck, it won't happen to others, but a heads-up nonetheless.

report abuse
vote down
vote up
David T
July 08, 2008
Votes: +0

Great thanks for the info Andrea! Glad you found it useful. Feel free to post the address of the site you've been using it on! Cheers.

report abuse
vote down
vote up
Marco
July 22, 2008
Votes: +0

Even with the changes you indicated to make it work with Joomla! 1.5, I still had a problem that appeared on all my site's pages:
Direct Access to this location is not allowed.

So, I made this change:
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
to:
defined( '_JEXEC' ) or die( 'Restricted access' );

Hope it helps. Thanks for tips. smilies/wink.gif

report abuse
vote down
vote up
Marco
July 22, 2008
Votes: +0

Hmmmm.... After posting my comment I've noted that Andrea had the same problem about Direct Access. I think the best way to solve this is to change the code as I mentioned before instead of turning legacy mode on smilies/grin.gif.

Cheers.

report abuse
vote down
vote up

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

busy
 
Ninjoomla

Latest comments

How to add Google An...
Ovo ti je dobar članak lafe. Hvala. Thi...
Sh404sef and Joomla ...
Hey andrie, just figured it out: Set the...
Sh404sef and Joomla ...
Hey andrie, I've got the same problem he...