[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: https://17thdegree.com/wp/page-restriction.phps
Any questions, comment here.
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.
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!
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;
17th Degree » WordPress Plugin: Page Restriction
17th Degree » WordPress Plugin: Page Restriction
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.
…seems…
Can I have it restrict access to a certain level of user?
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.
WordPress Plugin: Page Restriction…
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
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.
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?
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?
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?
I’m on 1.5.1.3 and I’ve also got the Tiger style admin and EZStatic installed
Try disabling EZStatic and then see if it still creates the error.
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
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.
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?
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
the link is dead to the .phps file 😉
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.
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.
[…] Also, this plugin is used in conjunction with my Page Restriction plugin. That plugin restricts certain pages to logged in users. […]
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…… 😉
Install went perfectly, but when I went to Options and restricted a test page, I got the following error:
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:
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.
Oh. Additionally, deactivating the poll plugin, then deactivating and reactivating Page Restriction, yielded the identical error.
I had the same error as Holly Lisle, but without any other plugin activated. Can soebody help me?
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!
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!
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..”
forget what i wrote above.. too quick on the draw to ask.. i found everything i need. sorry to bother you
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’] …
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.
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
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.
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 .
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?
Hmm sorry about that. Should be this:
<?php check_the_user(); ?>
Unicode to the rescue!
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
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. 🙁
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 🙂
[…] Page Restriction Plugin […]
[…] 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. […]
[…]   Page Restrictionå¯ä»¥è®©ä½ 在åŽå°è®¾å®šä»»ä½•ä¸€ä¸ªé¡µé¢çš„被访问æƒé™ã€‚ access é¡µé¢ page æƒé™ […]
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
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
I got the same msg on my k2 site.
nice one sir. thanks for it works good with wp1.5
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.
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
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!