[UPDATE #3]
Updated to version 1.4
– There should be no more errors on install or activation/deactivation.
[END UPDATE #3]

[UPDATE #2]
Updated to version 1.3
[END UPDATE #2]

[UPDATE]
I’ve updated the plugin. I’m now at version 1.2.

Here is the changelog:
v1.2:
– added code check for the Page Access plugin, only used if installed

v1.1:
– used built in WordPress function dbDelta() to update database structure
– changed name of options subpanel

The link is the same, but the .phps file has been updated

Enjoy!
[END UPDATE]

I know I haven’t posted in a long time and I’m sorry. I’ve been… lazy? busy? Sure, those will work. I would also like to sincerely appologize for the complete and utter disarray that this site is in – don’t worry, I’m working fixing all that.

But on to the point of this post…

Because I’m using WordPress as a Content Management System for our up-coming intranet/web-app at work, I needed a way of keeping the regular folks out of our private section of the site.

So, I wrote this plugin – Page Restriction – and it does just what it says, pretty much. It will add an Administration panel under the Options section, entitled Page Restriction – Clever huh? There you can pick and choose whatever pages you want restricted to logged-in users.

You may download the source here: http://17thdegree.com/wp/page-restriction.phps

Any questions, comment here.

117 Responses to “WordPress Plugin: Page Restriction”

  1. Hoover Says:

    Excellent plugin. The only problem I had was I had to disable the DB update/install routine in order for it to not throw an error… but, after my first change using the admin interface, the error was gone, even after putting the update/install routine back in.

    I’m sorry I didn’t save the error or I report it to you.

  2. James Says:

    Was it something like “can’t update table ‘wp1_posts’ because column already exists”? If so, that’s nothing to worry about. It is just trying to add a column that is already there. It shouldn’t have given that error, however. It has done that before when I disabled, then re-enabled the plugin.

    I really should make it check to see if that column is already in there… But I’m too busy at the moment, perhaps I’ll get some time soon.

    Thanks again!

  3. Hoover Says:

    WordPress database error: [You have an error in your SQL syntax near '; ' at line 1]
    alter table wp_hooverposts add restricted tinyint(1) not null default 0;

  4. ronny james disco Says:

    17th Degree WordPress Plugin: Page Restriction
    17th Degree » WordPress Plugin: Page Restriction
    Because Im using WordPress as a Content Management System for our up-coming intranet/web-app at work, I needed a way of keeping the regular folks out of our private section of the site.
    …seems…

  5. Mary-Ann Horley Says:

    Can I have it restrict access to a certain level of user?

  6. James Says:

    Currently, no, however, I was thinking of doing that for as a “Version 2″ thing.

    I may end up writing an entire complementary plugin for that, though, as I have similar needs.

  7. [i:rrhoblog] : linkdump Says:


    WordPress Plugin: Page Restriction…

  8. Mary-Ann Horley Says:

    I’m getting seveeral of these when I try to go to a page while not logged in

    Warning: Cannot modify header information - headers already sent by (output started at /home/kartlink/public_html/pro/wp-content/themes/gentle_calm/header.php:5) in /home/kartlink/public_html/pro/wp-includes/pluggable-functions.php on line 109

    If you (or anyone else) could point me in the right direction I could probably sort it out

  9. James Says:

    Proper redirects are done like this:

    < ?php
    header("Location: http://www.example.com/"); /* Redirect browser */
    ?>

    Before that code is executed, however, there must not be anything written out to the page. So it seems as though something is writing to the page – perhaps another plugin? – before the execution of my plugin.

  10. Dave Zan Says:

    Hi! Thanks for the plug-in, it’s what I’m looking for!

    However, when I click on Page Restriction, it doesn’t give me any option to choose any page to restrict access. I only see the Update Options button.

    Is there something else I need to do?

  11. Martin Says:

    Hello!

    I have the same problem as described above. The plugin is activated and some of the warnings appear within the first call. After this everything seems to be ok, but – as Dave says – no option to restrict access of pages!?
    Can you help?

  12. James Says:

    Hmmm, I can’t see any way that could happen. The main code for the displaying of pages is stolen out of the built in WordPress install.

    What version of WordPress are you using? I’ve only tested on version 1.5.3.

    Also, are you using any other plugins? If so, which ones?

  13. Mary-Ann Horley Says:

    I’m on 1.5.1.3 and I’ve also got the Tiger style admin and EZStatic installed

  14. James Says:

    Try disabling EZStatic and then see if it still creates the error.

  15. Mary-Ann Horley Says:

    I’ve just done that, no change. I also switched to the default theme instead of the one I’ve fiddled with. Thanks for all your help – feel free to tell me to take it to the wp forums if you’re bored of it

  16. James Says:

    Mary-Ann: Your problem is that somehow something is being written to the page – some HTML – before the header-redirect is being sent, which is not allowed. I hate to say “it’s not my plugin’s fault,” but I can’t see how it is. My plugin is hooked at “wp_head” which shouldn’t have anything being written at that point. You may have some success taking it to the WordPress forums. I’ll keep investigating.

    Mario: Actually, I’m writing something that does just that. I couldn’t find anything either. I may end up combining it with my Page Restriction plugin or I may keep it separate, but keep checking back her for updates on when I finish it.

  17. Mary-Ann Horley Says:

    Yeah, from the errors it doesn’t look like it’s anything to do with the plugin to me either – it just only happens with it installed. What should I be seeing when I’m logged out and go to a page, just out of interest?

  18. James Says:

    It should automatically redirect you to /wp-login.php. Also, whatever page you tried to access while not being logged in will be appended the link as a location to redirect you to once you do log in. For example: http://example.com/wp-login.php?redirect_to=%2Fpage-name%2F

  19. Latrans Says:

    the link is dead to the .phps file ;)

  20. Neil Says:

    Hi James,

    Thanks for the plug-in.

    I got the same problem with the page headers, but seems to me that this is a result of the initial click on the link before the plug-in takes over.

    I got around the problem by stripping the headers out of the log-in and doing a require() for a headerless log-in rather than a re-direct. (So that the log in page uses the original headers) – OK! Quick and dirty from a non-programmer, but it does the job. Still got a bit of customisation to do with the log-in pages, but basically it works.

    I have a custom menu at the top of my site and it works well with that also.

    You can check it out at http://www.mybusiness-mylife.com

    BUT, the big problem is when someone does a search from your front page, it still lists and shows the restricted pages.

    Maybe you can patch that? Thanks again.

  21. James Asher Says:

    Sorry about the missing link for the .phps file. I cleaned up a bunch of files and accidentally moved it.

    I’ve already updated the plugin for some clean up, as well as allowing it to integrate with my new plugin which should be done by tomorrow.

    As for the search picking it up, I’ll look into that and get back to you.

    Thanks again for your continued interest.

  22. 17th Degree » Blog Archive » WordPress Plugin: Page Access Says:

    [...] Also, this plugin is used in conjunction with my Page Restriction plugin. That plugin restricts certain pages to logged in users. [...]

  23. Neil Says:

    Hi James,

    Thanks for the upgrade. Loaded 1.3 and again got the headers already loaded problem, but used my headerless wp-login.php work around again as above to get it going again.

    Forgot that I was using RandomFrequency’s “Search Pages” plug-in, so it may have been that that brought the restricted pages up in the search rather than any fault with your plug-in.

    – be nice to have to interoperability between the two plug-in’s though…… ;-)

  24. Holly Lisle Says:

    Install went perfectly, but when I went to Options and restricted a test page, I got the following error:

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=2

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=1 where ID=3

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=5

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=6

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=7

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=8

    Reading through the comments, I tried deactivating and then reactivating the plugin, but received the same error.

    The header on the page that I tested remained accessible while I was logged out, but had the following message at the top:

    WordPress database error: [Unknown column 'restricted' in 'field list']
    select restricted from wp_posts where ID=3

    I’d greatly appreciate any help you can offer on where I’ve gone wrong here. I’m using WordPress 1.5.1.3, and the Democracy poll plugin.

  25. Holly Lisle Says:

    Oh. Additionally, deactivating the poll plugin, then deactivating and reactivating Page Restriction, yielded the identical error.

  26. mazzi Says:

    I had the same error as Holly Lisle, but without any other plugin activated. Can soebody help me?

  27. James Says:

    Holly Lisle, mazzi – I think that would be a problem of the restricted column not being created in the table.

    But no longer, I got some help on the WordPress forums and I’m now using the built-in function maybe_add_column and now there are no more DB problems or errors.

    At least that’s what I’m seeing. So here’s to it working!

  28. mazzi Says:

    I thought it was something like that, but i haven’t that expirience with php for correcting this.

    Anyway thanks for the very quick reaction, this isn’t normally on the internet. By the way you made a great job with this plugin!

  29. ptryk Says:

    giving this plugin a go; seems to be what i’m look’n for..

    1st .. in order to get it to show up in the “plugin management” to activate, i had to change the name to *.php instead of *.phps .. is this ok?

    2nd .. x’cuse the newB problem, but could someone post a screen shot of what exactly option this gives you when you “write post”.. once activated i see (in the imortal words of sgt. schultz), “..nothing..”

  30. ptryk Says:

    forget what i wrote above.. too quick on the draw to ask.. i found everything i need. sorry to bother you

  31. Markus Says:

    Hi all,

    I had the “Header already sent” error, too, here’s how i fixed it, a little hacking is required:

    1. Open the file /wp-includes/pluggable-functions.php
    Page Restiction calls the function auth_redirect(). Add another funtion to the file, that does not use the php header function that causes the warning.
    Here’s the code:

    if ( !function_exists(‘auth_redirect_mod’) ) :
    function auth_redirect_mod() {
    // Checks if a user is logged in, if not redirects them to the login page
    if ( (!empty($_COOKIE['wordpressuser_' . COOKIEHASH]) &&
    !wp_login($_COOKIE['wordpressuser_' . COOKIEHASH], $_COOKIE['wordpresspass_' . COOKIEHASH], true)) ||
    (empty($_COOKIE['wordpressuser_' . COOKIEHASH])) ) {
    echo ”;
    exit();
    }
    }
    endif;

    2. safe, close and upload the file.

    3. open page restirction plugin code and tell the script to call ‘auth_redirect_mod’ instead of ‘auth_redirect’ in line 195:
    Code:
    if (” == $user_ID) {
    auth_redirect_mod();
    } else {

    4. safe, close and upload the file.

    Not as perfect as the original file using thephp header function, but it works ;)

    Maybe anyone knows how to include the plugin file to make it fully compatible, I had some problems with the echo of $_SERVER['REQUEST_URI'] …

  32. Aaron Says:

    Hi, I also get the header error. I updated my WP 1.5.1.3 to WP 1.5.2, then installed the plugin and got the error.

    I have another WP 1.5.1.3 where I installed Page Restriction and Page Access first, then upgraded to WP 1.5.2. The error occurred while I had 1.5.1.3, but resolved once I upgraded to 1.5.2.

    WordPress database error: [You have an error in your SQL syntax near '; ' at line 7]
    select distinct page from wp_page_access_group_line_item inner join wp_page_access_user_line_item using(group_id) where wp_page_access_user_line_item.user_id = 1 order by page;

    Warning: Invalid argument supplied for foreach() in /home/virtual/site14/fst/var/www/html/wp-content/plugins/page-restriction.php on line 221

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/bizzcomm/header.php:4) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 129

    I’ve looked at the Codex regarding header errors, but the solutions doesn’t apply here.

  33. Aaron Says:

    P.S. using just the Page Restriction plugin without Page Access, I get:

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/bizzcomm/header.php:4) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 109

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/bizzcomm/header.php:4) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 110

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/bizzcomm/header.php:4) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 111

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/bizzcomm/header.php:4) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 112

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/bizzcomm/header.php:4) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 114

  34. Aaron Says:

    I’ve also posted this in the page-restriction thread in the WordPress support forums.

    Ok, I think I solved it. Not sure if I’m implementing the fixes “correctly,” but everything works now.

    To fix:

    WordPress database error: [You have an error in your SQL syntax near '; ' at line 7]
    select distinct page from wp_page_access_group_line_item inner join wp_page_access_user_line_item using(group_id) where wp_page_access_user_line_item.user_id = 1 order by page;

    Find this part in page-restriction.php:

    select distinct page
    from wp_page_access_group_line_item
    inner join wp_page_access_user_line_item
    using(group_id)
    where wp_page_access_user_line_item.user_id = $user_ID
    order by page;

    Put the above part all on one line so it looks like:

    select distinct page from wp_page_access_group_line_item inner join wp_page_access_user_line_item using(group_id) where wp_page_access_user_line_item.user_id = $user_ID order by page;

    To fix:

    Warning: Invalid argument supplied for foreach() in /home/virtual/site14/fst/var/www/html/wp-content/plugins/page-restriction.php on line 221

    Find this line in page-restriction.php:

    foreach ($pages as $k => $v) {

    Change it to:

    foreach ((array)$pages as $k => $v) {

    Finally, the infamous header error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/virtual/site14/fst/var/www/html/wp-content/themes/default/header.php:5) in /home/virtual/site14/fst/var/www/html/wp-includes/pluggable-functions.php on line 129

    Remove this line from page-restriction.php (near the end):

    add_action(‘wp_head’, ‘check_the_user’);

    Open your theme’s header.php and put this before everything, make sure there are no spaces/tabs/lines before it:

    Note, becareful if you’re using Notepad, apparently it puts 3 lines above the first line that you see… If it says the problem is on header.php line 4 after you do it, then open up the file in Wordpad and delete the 3 lines above it.

    Hope this helps.

  35. Aaron Says:

    Sorry, the PHP code got cut out.

    This should read:

    Open your theme’s header.php and put this before everything, make sure there are no spaces/tabs/lines before it:

    [?php check_the_user(); ?]

    Change the [] to .

  36. Sebastian Says:

    Eh, I just tried that and I believe this should be corrected to:

    [?php check_the_user(); ?]

    AND change these [] to to ”

    Or am I wrong here?

  37. Sebastian Says:

    Hmm sorry about that. Should be this:

    <?php check_the_user(); ?>

    Unicode to the rescue!

  38. Will Says:

    Hey,

    I am getting these erros in the dashboard. Seem to be different than all the ones above:

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-admin/admin.php on line 10

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-admin/admin.php on line 11

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-admin/admin.php on line 12

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-admin/admin.php on line 13

    Those lines in admin.php are simply:

    header(‘Expires: Wed, 11 Jan 1984 05:00:00 GMT’);
    header(‘Last-Modified: ‘ . gmdate(‘D, d M Y H:i:s’) . ‘ GMT’);
    header(‘Cache-Control: no-cache, must-revalidate, max-age=0′);
    header(‘Pragma: no-cache’);

    Now of course getting rid of those four lines fixed the problem but I want to make sure that wont brake anything?

    Thanks for any help,
    Will

  39. Will Says:

    Hey,

    Well just loged out to see if plugin works.

    And I get:

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 7

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 8

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 9

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 10

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 11

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-includes/pluggable-functions.php on line 163

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-includes/pluggable-functions.php on line 164

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-includes/pluggable-functions.php on line 165

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-includes/pluggable-functions.php on line 166

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 27

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 28

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 29

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-login.php on line 30

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/blog/wp-includes/pluggable-functions.php on line 129

    Wow!!!!

    So now I cant log out. lol

    So of course i can still see page.

    Also, on every page but the one i said no access to I get:

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/jpcache/jpcache-main.php on line 170

    Warning: Cannot modify header information – headers already sent by (output started at /home/.darkstar/war59312/willsdownloads.com/blog/wp-content/plugins/page-restriction.php:429) in /home/.darkstar/war59312/willsdownloads.com/jpcache/jpcache-main.php on line 11

    :(

    Looks like this plugin needs some serious work. :(

  40. Jan Says:

    Just change this line in page-restriction.php (near the end)
    add_action(’wp_head’, ‘check_the_user’);
    to
    add_action(‘template_redirect’, ‘check_the_user’);
    instead of deleting it or modifying your template.

    Works for me :)

  41. Web Initiatives » Plugins Says:

    [...] Page Restriction Plugin [...]

  42. Password Protect WordPress Pages at The Geek Blog Says:

    [...] James Asher wrote a plugin called Page Restriction that allows you to block pages that you explicitly state. I needed to tweak it slightly to allow the failed attempt to prompt for login properly, but a user named Aaron posted exactly how to fix this in the comments section. [...]

  43. Blogging Pro China » Blog Archive » WordPress Plugin: Page Restriction Says:

    [...]   Page Restriction可以让你在后台设定任何一个页面的被访问权限。 access 页面 page 权限 [...]

  44. Jeremy Carlson Says:

    Great idea,

    For me it’s not quite fleshed-out enough, though. I’d love to see this affect the wp_list_pages() function, so that if the user isn’t logged in, they don’t see this show up in the list. Thought of adding a page to the excluded parameters of that tag, but then NOBODY can see it.

    Same as a lot of folks, I’m building a CMS around WordPress, and this would be a great way to provide a Help region that only people logged in could see.

    Good luck in your programming efforts. I’m doing my own work on a plugin for WP and it gets darn hard. That’s the problem w/ PHP – you start to get a taste for what you can do, and you have these great ideas… just. need. to. figure. out. how.

    -Jeremy

  45. Miklo Says:

    I got the following msg in k2 theme

    Warning: Cannot modify header information – headers already sent by (output started at C:\Program Files\xampp\htdocs\wp-content\themes\k2betatwor163\js\livesearch.js.php:91) in C:\Program Files\xampp\htdocs\wp-includes\pluggable-functions.php on line 221

  46. 2Feek Says:

    I got the same msg on my k2 site.

  47. yoga Says:

    nice one sir. thanks for it works good with wp1.5

  48. keira Says:

    I used to have the same problem with the “header” but after following the simple step stated by Jan on November 25th, 2005 at 12:33 pm *points up* it works perfectly fine :)

    Thank you James for the script and for everyone that kindly helped out with the codings.

  49. Sadish Says:

    I have it installed, and also did the fix as mentioned above. it does shows the page to everyone. restriction is not in effect at all.

    Please help

    Thanks

  50. Kelley Says:

    I’m not sure if your code will do what I’m wanting or not, so I’ll ask first before I dive into it… when someone logs onto my blog, they get previews of every entry made… whether they’ve registered or not. The only priviledge they don’t get is to post… however, if you 17thDegree code works the way I’m thinking it does, will it prevent non-registered users from seeing those updated posts and viewing any posts unless registered??? If not, would you know where I can find something for that? PLUS, I’m still getting a good grasp of coding, so exactly how would I place that code into my site? Where? What words do I change to fit my site??? Please help… thanks!

  51. Jeremy Carlson Says:

    Shoot, now I’m trying to use this w/ WP 2.0.2, and I’m getting the ‘cannot modify header information’ error that others have encountered. Wonder if I can connect it to an earlier API hook…?

  52. Jeremy Carlson Says:

    Clearly I’m just tired. I hadn’t read through all the earlier comments. NOW I have. I tried several of the fixes but none seemed to work. When I added the function above wp_head in my header.php, it just displayed the ‘restricted’ file whether I was logged in or not.

    But Jan’s suggestion above seemed to do the trick. It’s ugly, but it’ll work for my purposes. I’d love to hear if there’s a more graceful fix. But I’ll probably have to look more carefully at my other plugins…

    Thanks,
    Jeremy

  53. farm Says:

    anyone having problems with 2.0.2 compatibility ?

  54. jweaks Says:

    Neat little plugin… got it working with WP 2.0.2, used Jan’s hack above.

    I would love to see a user level check (or user role check) added.

    Anyone know how to hack it so the user has to be at or above a cetain level?

    Level 1 or “Contributor” role would do… just need it a notch above public access.

    jweaks

  55. jweaks Says:

    I looked at the code and compared it to another plugin that checks for levels and I was able to do the hack myself.

    I don’t know if it’s good code, but it works:

    CODE starts at line 191′

    global $user_ID, $user_level; // jweaks added $user_level
    get_currentuserinfo();
    // is user already logged in?
    $user_level = $userdata->user_level; // jweaks added line
    if ($user_level == 0) { // jweaks added line
    // if (” == $user_ID) { // jweaks commented out line
    auth_redirect();

    ‘end code

    jweaks

  56. Matt Says:

    Thanks, great plugin.
    Used it on WP 2.0.
    It’s just I got this silly idea about making another plugin based on yours.
    Is it okay for me to start out using the code from your plugin ?
    Well, it’s just a silly thought, who knows.
    Well, you got my email.
    Thanks anyway.

  57. Carsten Says:

    Hi! Got the headers-sent-problem too although having tried the workarounds… Also tried switching the other plugins on and off – no success.
    Another workaround anyone? – here’s mine:

    1. Open page-restriction.php (plugin script)
    2. Edit lines between from #189 and save. It should then look like this:
    code’
    if ($isrestricted == 1) {
    global $user_ID;
    get_currentuserinfo();
    // is user already logged in?
    if (!is_user_logged_in()) { // as defined in pluggable-functions.php
    // call alternative auth_redirect
    // thx to Markus :-)
    auth_redirect_mod();
    } else {
    // This is checking to see if the Page Access plugin is installed
    ‘end code
    Sorry: I can’t tell you line numbers explicitly – tinkered too much.

    3. Open wp-includes/pluggable-functions.php
    4. Insert modified auth_redirect function (and of course save):
    code’
    if ( !function_exists(’auth_redirect_mod’) ) :
    function auth_redirect_mod() {
    // Checks if a user is logged in, if not redirects them to the login page
    if ( (!empty($_COOKIE[’wordpressuser_’ . COOKIEHASH])
    && !wp_login($_COOKIE[’wordpressuser_’ . COOKIEHASH], $_COOKIE[’wordpresspass_’ . COOKIEHASH], true))
    || (empty($_COOKIE[’wordpressuser_’ . COOKIEHASH])) ) {
    //kind of shortcut
    $filename = get_settings(‘siteurl’) . ‘/wp-login.php?redirect_to=’ . urlencode($_SERVER['REQUEST_URI']);
    // have a look at Jacob’s solution on http://de.php.net/manual/de/function.headers-sent.php#60450
    if (!headers_sent())
    header(‘Location: ‘ . $filename);
    else {
    echo ”;
    echo ‘window.location.href=”‘.$filename.'”;';
    echo ”;
    echo ”;
    echo ”;
    echo ”;
    }

    exit();
    }
    }
    endif;

    ‘end code

    Good luck :-)
    Carsten.

  58. Valentine Says:

    Looking for the same functionality as jweaks – checking for user level or role as well as registration. I tried the hack provided but couldn’t get it to work; anyone with registration regardless of level could still see the restricted pages. Any ideas?

  59. Rene Says:

    Hi,

    when not registered or logged in I get the statement:

    Warning: Cannot modify header information – headers already sent by (output started at /storage/mijndomein/users/011971/public/sites/www.polyplatform.nl/wordpress/wp-content/themes/polyplatform/header.php:7) in /storage/mijndomein/users/011971/public/sites/www.polyplatform.nl/wordpress/wp-includes/pluggable-functions.php on line 220

    When logged in all goes well…

  60. Jan Brašna Says:

    James, the “headers already sent” issue is because the ‘wp_head’ stuff is being processed in the part of HTML – after a lots of output. You might not see it if your host is using output buffering. One of the pretty good hooks could be ‘template_redirect’ instead.

  61. Jesse Says:

    Jan’s fix worked like a champ!

  62. Katie Says:

    Hello I tried restricting a page and when I click on it when not logged in, it says , “OK The document has moved here.” Then I click ‘here’ and I can log in. Can I get rid of the ‘OK’ page??

  63. Bryan Says:

    Is there any way to hide the restricted pages from unregistered users / keep from showing up when calling wp_list_pages?

  64. Jon Says:

    ** OK The document has moved here. **
    Firstly, on the subject of getting rid of the “OK The document has moved here.” message. I found a suggestion for the solution http://wordpress.org/support/topic/77094
    It’s bascially being caused by the fact that WP thinks the redirect is sending you to an invalid url. So it brings up this nice message screen instead. The suggested solution worked, but I think it may well be removing some other CORRECT functionality you could miss later on.

    ** Restricting results of wp_list_pages **
    To change this means changing the contents of ‘template-functions-post.php’, which is obviously a bad thing. However, seeing as I wanted to remove the links on my site too, here’s what I did.
    In the file template-functions-post.php’, you’ll find a fuinction titled ‘get_pages’.

    In the middle of the function where it’s building the sql, I replaced the following:
    $pages = $wpdb->get_results(“SELECT * ” .
    “FROM $wpdb->posts ” .
    “WHERE post_status = ‘static’ ” .
    “$exclusions ” .
    “$no_restricted ” .
    “ORDER BY ” . $r['sort_column'] . ” ” . $r['sort_order']);

    with:
    // Added logic to check if the page_restriction plugin is active.
    $no_restricted = ”;
    $current_plugin_status = get_settings(‘active_plugins’);
    if (in_array(‘page-restriction.php’, $current_plugin_status))
    {
    global $user_ID;
    if (” == $user_ID)
    $no_restricted .= ‘ AND restricted = 0 ‘;
    }

    $pages = $wpdb->get_results(“SELECT * ” .
    “FROM $wpdb->posts ” .
    “WHERE post_status = ‘static’ ” .
    “$exclusions ” .
    “$no_restricted ” .
    “ORDER BY ” . $r['sort_column'] . ” ” . $r['sort_order']);

    Note that my solution is only for the page_restriction plugin. If you’re using the page_access plugin too, then you’ll have to figure it out.

  65. Wordpress Plugins tried successfully for our Church Website at Cambray « Blog of the Webeditor of Cambray.org Says:

    [...] Advanced options for Pages. Includes Search Pages by David B. Nagle and Page Restriction by James Asher. More info… By Dave Mitchell . [...]

  66. Steve Says:

    Will you be updating your plugins to work with 2.1?

  67. James Asher Says:

    I haven’t been doing much with my extensions lately, but have recently been inclined to take another look at them.

    No promises, but there is a good chance I’ll be taking another look at them again soon.

  68. Daniele Says:

    Parse error: parse error, unexpected ‘}’ in C:\wamp\www\wordpress\wp-content\plugins\page-restriction.php on line 160

  69. skridge Says:

    nothing shows under Options|restrict pages. it’s completely blank. this is with a fresh install of newest wp. nothing else has been installed except a modded theme with new gfx.

  70. Will G. Says:

    Has anyone tried Jan’s fix to get rid of the header warning only to have the page end up visible to everyone – logged in or not? if you have had this problem – how did you fix it?

    Thanks!

  71. aircow33 Says:

    when a user click on a restricted page it will not redirect to the login page. Auth_redirect doesnt seem to work. No error shows up only a black screen.

    -stan

  72. Michelle Says:

    FIX for 2.1 issue of nothing showing up on admin (Options / Page Restriction) page:

    Open page-restriction.php and replace all instances of

    $wpdb->posts.post_status = ‘static’

    with

    $wpdb->posts.post_type = ‘page’

    Your pages should now show up on the admin (Options) page.

  73. Shilo Case Says:

    Hi James, I’m excited about your plugin but when I activate it and go into Options/Page Restriction, it says, “no pages yet.” I refresh Options and it still says “no pages yet.” I have two pages listed in my Manage/Pages section but they don’t show up on the Page Restriction page. Why is that? Do I have to specify the pages to be somthing specific?

    Regards,
    Shilo Case

  74. Shilo Case Says:

    I found out why the page is not showing up on the Page Restriction page. It’s because the page status is set to Publish. The only options in WordPress are Publlish, Draft, and Private. The only status in MySQL that will work is Static. However, is disappears from the Manage/Page area and disappears as a link on the BLOG site. I’ve tried adding a link on the Theme Header and Functions page so it looks like the link from Pages is there but upon clicking it, while not logged in, it gives me a “page can not be found.” If I log in through my admin login link and then go back to the main URL page and click on the link, it goes straight to the Forum page I want to pass word protect. ANy ideas?

    Regards,
    Shilo Case

  75. Tom Bond Says:

    Our new site at http://www.theplayersguidetoplaying.com is using WP 2.1. We are trying to create a ‘members only’ page so people who have paid can come back to download the audio MP3 version of our book.

    We installed the page-restriction.php and changed the
    $wpdb->posts.post_status = ’static’

    with

    $wpdb->posts.post_type = ‘page’

    however, still no pages are showing up in the
    Options->Page Restriction menu page. Just says
    ‘no pages yet’.

    Any ideas?

  76. peter Says:

    The alleged fix seems to be
    WHERE post_status = ‘static’
    and tehre are 3 insatnces to replace with
    WHERE post_status = ‘page’

    I edited it but getthe same NO PAGE Sfound.
    If I do an update options, it is apparent that teh database field doe snot exist.

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=1

    Shame, because with page group, it would be a great solution…..

  77. Seth Says:

    I also get the same ‘no pages yet’ message and have tried tweaking the SQL in the page-restriction.php file but with no luck. I’m not totally familiar with the db structure.

    Is there a fix to this plugin. It sounds like exactly what I need.

    Thanks!
    seth.

  78. Seth Says:

    I just found a fix that seems to work. The WHERE clauses need to be changed to use the post_type field, not post_status:

    Line 81:
    WHERE $wpdb->posts.post_type = ‘page’

    Line 85:
    $posts = $wpdb->get_results(“SELECT $wpdb->posts.* FROM $wpdb->posts WHERE post_type = ‘page'”);

    Line 123:
    $pages = $wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_type = ‘page’ ORDER BY menu_order”);

    Then my pages appear under Options > Page restriction and I’m able to select the pages that require a logged-in user. When that page is selected in the menu, user is immediately taken to the login screen.

  79. Ivy Says:

    Seth’s fix posted above this let me see the pages under Options > Page restriction, but I still get this when I try to Update Options with restricting one of my pages:

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=1

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=2

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=1 where ID=3

    anybody know how to fix this?

  80. Immow Says:

    After reading like 50 posts I manged to change the code so that it works.

    ####Part 1 comment Seth####
    Line 81:
    WHERE $wpdb->posts.post_type = ‘page’

    Line 85:
    $posts = $wpdb->get_results(“SELECT $wpdb->posts.* FROM $wpdb->posts WHERE post_type = ‘page'”);

    Line 123:
    $pages = $wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_type = ‘page’ ORDER BY menu_order”);

    Then my pages appear under Options > Page restriction and I’m able to select the pages that require a logged-in user. When that page is selected in the menu, user is immediately taken to the login screen.
    ####part 2 comment Jan####
    You find this code at the bottom

    add_action(‘wp_head’, ‘check_the_user’);
    to
    add_action(‘template_redirect’, ‘check_the_user’);

    ####Bugs####
    – Opera takes a long time to load a restricted page (1 second or so)
    – The plugin is gone from my plugin directory in wordpress but the admin pannel for pagerestriction is still there.

  81. Jim D Says:

    We were getting the same header error that lots of people here have reported:

    Warning: Cannot modify header information – headers already sent by (output started at /home/kartlink/public_html/pro/wp-content/themes/gentle_calm/header.php:5) in /home/kartlink/public_html/pro/wp-includes/pluggable-functions.php on line 109

    The fixes suggested above weren’t working for us…not sure why but possible because we’re on WP 2.1.

    Anyhow, I wanted to share the solution that did work:

    Change:

    add_action(’wp_head’, ‘check_the_user’);

    To:

    add_action(‘get_header’, ‘check_the_user’);

    The add action function calls WP hooks, and using the get_header hook as opposed to the wp_head seemed to do the trick. Here’s the page in the codex that discusses these hooks, as an FYI:

    http://codex.wordpress.org/Plugin_API/Action_Reference

    Hope this helps someone!

  82. Phil H Says:

    Hi, this plugin looks like what I need. But I see no posts here for a couple of years!

    Will the plugin still function with WP2.2, any idea?

    Thanks

  83. KP Says:

    Is this plugin ready for use? I read so many error and bug, anyone has success so far, I would like to have the plugin on my blog but I would like to ask for some opinion first.

    Thank you.

    KP

  84. Mosey Says:

    I can confirm that Immow’s solution (Comment #80) works for 2.1.3. Thanks!
    I was keen to avoid any extra load time and such as mentioned, so I decided to try Jim D’s suggestion, but for some reason it gave me another header error. >_

  85. Graeme Says:

    I have now created a tweaked version that works for me with WP 2.2.1.

    The errors on update are gone and the redirect and page listings are working perfectly.

    G

  86. alias Says:

    on the latest WP the plugin won’t activate

    Plugin could not be activated because it triggered a fatal error.

  87. Arvin Says:

    graeme, are u planning to make ur version available?

  88. Graeme Says:

    Go to the download library on my site and you’ll find it.

    I’ve made a forum on my site for any bugs, etc. Can’t make any promises on support, but as I’m an over-eager geek, who knows.

  89. Restricting User Access « N0T a Blog Says:

    [...] “Page Restriction” – works nicely with “Page Access” (which implements a proprietary Roles system). [...]

  90. Andrei Says:

    I get this message under Options/Page Restrictions:

    No pages yet.

    Why is it not recognizing my pages?!

  91. Mosey Says:

    Thanks Graeme :) I haven’t upgraded to WP 2.2+ yet but once I do I’ll be sure to use your plugin.

  92. Kate Says:

    I don’t understand how it works! I uploaded it to my plugins folder, what now??? Please, HELP!

  93. Kate Says:

    Sorry for the double post, I figured it out now, but I’m getting these errors:

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=0 where ID=1

    WordPress database error: [Unknown column 'restricted' in 'field list']
    update wp_posts set restricted=1 where ID=2

    and this shows on the page:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
    select restricted from wp_posts where ID=

    Does anyone know how to fix this?

  94. davide Says:

    I’ve just installed your plugin.
    I only see the Page Restriction Options Panel but in this panel I only see the label “No pages yet” and the button “Update Options”.

    I haven’t found any more in order to restrict the access to a specific page.

    How could I add any pages to the restriction list?

    Thanks

    Davide Taibi

  95. Manele Says:

    I have just installed your plugin on a new blog I am doing and first – thank you!

  96. Balint Says:

    Hi there!

    I’ve installed the plugin and it works fine from the first time, so it’s a great job and thank you for that plugin. I would like to make the plugin to add all registered user to a group. So my goal is to see when someone registers he/she will be able to watch the pages and don’t need to add them to a group manually. I want to automatize that.
    Can you help me somehow, or give a code to add please?

    Thanks
    Balint

  97. Charlotte Says:

    I am also getting the message, no pages yet.
    I am running WP 2.2.

    Help and advice much appreciated. Thank you :)

  98. Erik Cederstrand Says:

    There’s a small bug in line 115 in v. 1.4

  99. na3s Says:

    The bug that he is speaking of is that in v.1.4 you used a shorthand php opening tag excluding the text ‘php’ after [

  100. misha Says:

    Hi,

    actually I wanted to use your plugin, though it eems that even after correcting the previously mentioned bug in 1.4 it still won’t show any pages in the options panel. It doesn’t even show an error, it just doesn’t show anything.
    I would greatly appreciate any help.

    I am using WP 2.3.1

  101. Adam Dexter Says:

    This guy has fixed both this plugin and Page Access for WP2.3.2

    I’m using it now.

    http://bytor.co.uk/library

  102. Adam Dexter Says:

    just kidding, the page restrictions won’t stick.

  103. Chaos Inc. Says:

    Same problem as the above user. Am using 2.3.1 but when its showing no pages yet. I want to restrict users to a page unless they subscribe. Is there any way that can be done?

  104. Eric Hamby Says:

    im using 2.2.1 and im getting the no pages added yet on the options page. i see im not the only one. any word yet what is doing this?

  105. levani Says:

    I installed it but don’t know how to use. Please help.

  106. Özer Says:

    Same problem with everyone.”No pages yet.!!” Is there anyone who solve this problem? Please share us your solution about this problem.

  107. ian Says:

    I have the plugin working but when I go to restrict pages using the selection boxes and hit update, I get the notice that it was updated but the tick marks aren’t there any more and the pages aren’t restricted. Is there something I’m missing. I’m using WP2.3 and the latest fixed version of page restriction from Graeme(poster above). Same thing happens with page access – pages show up and allows me to tick the boxes off and text in the fields but after I hit the create or save button it says its saved but nothing is added to groups and the check boxes are blank once again. Please lend me your insights.

  108. Plantillas para Blogger, recursos y herramientas » 22 plugins para mejorar la seguridad de tu blog con WordPress. Says:

    [...] Page Access. Crea grupos de páginas y selecciona los usuarios registrados que pueden acceder a los mismos. La página está asociada a un grupo determinado, asociado a su vez a los usuarios que se desee permitir la entrada. También te puede interesar el plugin Page Restriction. [...]

  109. AngryDude Says:

    This plugin is linked to all over the net as the only damn “working” page restriction tool …

    I install it, get no pages on the options page and I’m done.

    Can someone PLEASE tell me of a way to restrict certain pages on a wordpress blog based on a user being logged in???

  110. dino Says:

    Great plugin. Thanks so much!

    AngryDude – you need to get the page access plugin too and activate both of them. From there it should be easy to get going with the simple documentation. All the best.

  111. kris Says:

    Hi there. I’m quite new to wordpress; was wondering if anyone knows about using this plugin with 2.5.1. I installed it (Graeme’s update, many thanks) but unfortunately the check boxes don’t stay ticked in the restriction page, which is something I’ve read about elsewhere. I’m guessing it must be to do with my version of WordPress; any ideas?

  112. Kani Says:

    Hi there, I’m using WP 2.5.1 and have installed and activated both plugins, but there are no pages listed when I got to set up the Page Access settings (and I do have pages that have been created).

    Any help would be appreciated. Thanks!

  113. Joakim Says:

    I have a question about your page restriction plugin. I installed it and it seems to work. the page restriction appears in the panel under settings but it only says “no pages yet”. Where do I choose the pages that I want to restrict. I seems to be an old plugin so I am starting to wunder if it really works for the new wordpress.

    Cheers

    Joakim

  114. Joakim Says:

    Oh! now I read the whole thread hehe. It seems to be a few others having the same prob..

  115. Mosey Says:

    With reference to Graeme‘s comment, please visit his page for the fixed version of this plugin:
    http://bytor.co.uk/library

    It seems to work fine for me on 2.5.1.

  116. Aileen Says:

    Looks like a great plugin…. but it is now August 2008, WordPress 2.6 is with us and I have the same problem with this plugin that lots of other recent visitors have posted about – the plugin installs okay and appears nicely in the Admin pages but when you select Page Restriction it only says “no pages yet” and does not show your existing pages.

    There was a helpful link to a fix at http://bytor.co.uk/library but I wonder if it has had too many visitors… there is only a strange “Terms and Conditions of Use” page there now.

    Any helpful hints as to how to get this plugin to recognise existing pages?

    Are you planning to update it for WordPress 2.5 / 2.6?

    Thanks.

  117. JeremiahTolbert.com » Blog Archive » links for 2009-01-18 Says:

    [...] 17th Degree » Blog Archive » WordPress Plugin: Page Restriction for a project (tags: wordpress security restriction) [...]

Drop Some Knowledge On Us…