We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

NEW: LG Access (Restrict To)

Development and Programming

Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Hey guys,

I have just written a quick plugin that restricts templates to members with a specific id or that belong to a specific group.

I know you can restrict template groups but I also needed to restrict templates from certain members.

So I present LG Access (restrict to)…

Place the plugin code at the top of your template like so:

{exp:lg_access:restrict_to
    member_id = "1"
    redirect_to = "/members/login/access-denied"
}

and if the current member is not member 1 then they will be redirected to the redirect_to url.

The plugin also accepts member groups

{exp:lg_access:restrict_to
    group_id = "2"
    redirect_to = "/members/login/access-denied"
}

or multiple members delimited by a pipe

{exp:lg_access:restrict_to
    member_id = "1|2"
    redirect_to = "/members/login/access-denied"
}

or multiple member groupss delimited by a pipe

{exp:lg_access:restrict_to
    group_id = "1|2"
    redirect_to = "/members/login/access-denied"
}

I was planning to add a return_to param so once a user is logged in then they would be returned to the same page they where restricted from but that would involve session madness, unless someone else has a better idea?

The initial idea for this plugin came from comments in Mark Bowens Redirect Plugin which is much more flexible when it comes to standard redirects.

Grab the LG Access (Restrict To) plugin from my site.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

You must have read my mind with this one. I actually created a plugin to do exactly this and was going to release it!!

I made it pretty much around the same time as the Redirect Plugin as I needed this functionality for a site. Mine was literally cobbled together so I’m going to take a look at yours as I know your code will probably be a lot neater! 😉

Best wishes,

Mark

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Ha… great minds think a like…

Feel free to check out mine and maybe we can merge them together.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Not really. Mine works but yours has a little more functionality so it wouldn’t really be so much of a merge than a down-grade for yours!! 😊

I do think that you need to check some of your comments and such in the code though as it appears that you have some of your Latest EE version code names in there 😉

Best wishes,

Mark

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham
Not really. Mine works but yours has a little more functionality so it wouldn’t really be so much of a merge than a down-grade for yours!! 😊 I do think that you need to check some of your comments and such in the code though as it appears that you have some of your Latest EE version code names in there 😉 Best wishes, Mark

Yeah thats the beta, beta, first attempt part 😊 I’ll clean up the code and add some documentation to my site if you think this plugin will be useful.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Yep I know it will be useful as I made one myself that does the same thing so I know there is definitely a calling for it.

I’m sure others will find this useful too.

Well done on more great coding!

Speak to you soon.

Best wishes,

Mark

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Ok documentation is up!

Grab the LG Access (Restrict To) plugin from my site.

I added some blacklist/whitelist + banned member group checking as well for good measure.

Cheers Leevi

@Mark: There is some code in the plugin or handling URLs that you might find useful for your redirect plugin 😉

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

I know I know!! My coding is not the best. Was meaning to try and use the create url function. I did originally try it but for some reason couldn’t get it to work properly under every condition. Will probably take a look at it when I get a bit more time.

Well done on getting this up on your site with documentation so quickly. You really are a fantastic asset to the EE community!

Best wishes,

Mark

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

Leevi, my question to you is how do you accomplish making these things so quickly? You must have a fantastic grasp of how EE works. Thanks for all your stuff.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham
Leevi, my question to you is how do you accomplish making these things so quickly? You must have a fantastic grasp of how EE works. Thanks for all your stuff.

I have a pretty nice library of functions I can call on these days and my knowledge has increased over the last few months.

This one was actually needed for a client project so that always helps. I’m guessing the learning will have to start again in the next few weeks with EE 2.0 on the way :(

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
This one was actually needed for a client project so that always helps.

Mine too. Sometimes you just get pushed into having to figure out how to do something so that you can get a site working for a client 😊

I’m guessing the learning will have to start again in the next few weeks with EE 2.0 on the way :(

Please don’t remind me!! 😉

Can’t wait to see what goodies the EE crew have up their sleeves though!! 😊

Best wishes,

Mark

       
smartpill's avatar
smartpill
456 posts
17 years ago
smartpill's avatar smartpill

Looks pretty useful! Is there a straightforward way to combine this with LG Member List to assign member-specific access to an entry?

       
mmcclung's avatar
mmcclung
172 posts
17 years ago
mmcclung's avatar mmcclung

Any reason you can see for this error?

Notice: Undefined variable: IN in /usr/www/users/poc/mysite.com/system/plugins/pi.lg_access.php on line 89

Notice: Trying to get property of non-object in /usr/www/users/poc/mysite.com/system/plugins/pi.lg_access.php on line 89

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/poc/mysite.com/system/plugins/pi.lg_access.php:89) in /usr/www/users/poc/mysite.com/system/core/core.functions.php on line 296
       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham
Any reason you can see for this error?
Notice: Undefined variable: IN in /usr/www/users/poc/mysite.com/system/plugins/pi.lg_access.php on line 89

Notice: Trying to get property of non-object in /usr/www/users/poc/mysite.com/system/plugins/pi.lg_access.php on line 89

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/poc/mysite.com/system/plugins/pi.lg_access.php:89) in /usr/www/users/poc/mysite.com/system/core/core.functions.php on line 296

Yeah I’m guessing a global is not defined for the method… I’ll take a quick look at it now..

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Ok change line 63 of the plugin to be:

global $FNS, $IN, $SESS, $TMPL;

I’ll update the download asap

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.