WordPress Plugin: Page Restriction
Posted
- July 1st, 2005
Comments
- (111)Say something?
Tags
[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.
July 5th, 2005 at 3:13 pm |
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.
July 5th, 2005 at 3:34 pm |
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!
July 5th, 2005 at 5:41 pm |
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;
July 6th, 2005 at 3:13 am |
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…
July 6th, 2005 at 3:14 pm |
Can I have it restrict access to a certain level of user?
July 6th, 2005 at 3:19 pm |
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.
July 7th, 2005 at 4:07 am |
WordPress Plugin: Page Restriction…
July 8th, 2005 at 2:06 pm |
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 109If you (or anyone else) could point me in the right direction I could probably sort it out
July 8th, 2005 at 2:11 pm |
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.
July 9th, 2005 at 9:58 am |
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?
July 9th, 2005 at 3:26 pm |
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?
July 9th, 2005 at 10:22 pm |
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?
July 10th, 2005 at 7:45 am |
I’m on 1.5.1.3 and I’ve also got the Tiger style admin and EZStatic installed
July 10th, 2005 at 8:55 am |
Try disabling EZStatic and then see if it still creates the error.
July 10th, 2005 at 9:47 am |
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
July 11th, 2005 at 9:12 am |
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.
July 11th, 2005 at 2:07 pm |
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?
July 11th, 2005 at 2:19 pm |
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
July 19th, 2005 at 4:19 pm |
the link is dead to the .phps file
July 19th, 2005 at 5:51 pm |
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.
July 21st, 2005 at 7:29 am |
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.
July 21st, 2005 at 10:31 am |
[…] Also, this plugin is used in conjunction with my Page Restriction plugin. That plugin restricts certain pages to logged in users. […]
July 23rd, 2005 at 8:24 am |
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……
July 24th, 2005 at 10:29 am |
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.
July 24th, 2005 at 10:31 am |
Oh. Additionally, deactivating the poll plugin, then deactivating and reactivating Page Restriction, yielded the identical error.
July 25th, 2005 at 8:55 am |
I had the same error as Holly Lisle, but without any other plugin activated. Can soebody help me?
July 25th, 2005 at 9:20 pm |
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!
July 26th, 2005 at 2:10 am |
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!
July 28th, 2005 at 7:05 am |
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..”
July 28th, 2005 at 7:15 am |
forget what i wrote above.. too quick on the draw to ask.. i found everything i need. sorry to bother you
July 30th, 2005 at 6:43 am |
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’] …
August 17th, 2005 at 3:00 am |
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.
August 17th, 2005 at 3:04 am |
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
August 20th, 2005 at 2:03 am |
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.
August 20th, 2005 at 2:10 am |
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 .
September 19th, 2005 at 6:32 pm |
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?
September 19th, 2005 at 6:34 pm |
Hmm sorry about that. Should be this:
<?php check_the_user(); ?>
Unicode to the rescue!
November 11th, 2005 at 3:50 am |
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
November 11th, 2005 at 3:54 am |
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.
November 25th, 2005 at 12:33 pm |
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
November 30th, 2005 at 4:02 pm |
[…] Page Restriction Plugin […]
December 21st, 2005 at 10:31 am |
[…] 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. […]
December 30th, 2005 at 10:46 pm |
[…]   Page Restrictionå¯ä»¥è®©ä½ 在åŽå°è®¾å®šä»»ä½•一个页é¢çš„被访问æƒé™ã€‚ access é¡µé¢ page æƒé™ […]
January 8th, 2006 at 3:19 pm |
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
January 22nd, 2006 at 12:54 pm |
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
January 25th, 2006 at 12:28 pm |
I got the same msg on my k2 site.
January 29th, 2006 at 11:03 am |
nice one sir. thanks for it works good with wp1.5
February 12th, 2006 at 1:08 pm |
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.
February 17th, 2006 at 5:40 pm |
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
March 24th, 2006 at 10:42 am |
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!
March 29th, 2006 at 12:15 am |
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…?
March 29th, 2006 at 1:24 am |
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
March 31st, 2006 at 7:30 pm |
anyone having problems with 2.0.2 compatibility ?
April 6th, 2006 at 8:25 am |
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
April 6th, 2006 at 9:08 am |
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
April 14th, 2006 at 6:18 am |
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.
April 15th, 2006 at 3:11 pm |
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.
April 24th, 2006 at 7:33 am |
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?
April 28th, 2006 at 1:48 am |
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…
May 30th, 2006 at 6:22 am |
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.
June 20th, 2006 at 8:40 am |
Jan’s fix worked like a champ!
June 23rd, 2006 at 3:44 pm |
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??
June 30th, 2006 at 7:43 am |
Is there any way to hide the restricted pages from unregistered users / keep from showing up when calling wp_list_pages?
July 18th, 2006 at 1:45 pm |
** 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.
October 18th, 2006 at 5:26 pm |
[…] Advanced options for Pages. Includes Search Pages by David B. Nagle and Page Restriction by James Asher. More info… By Dave Mitchell . […]
January 25th, 2007 at 12:30 pm |
Will you be updating your plugins to work with 2.1?
January 25th, 2007 at 2:20 pm |
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.
January 29th, 2007 at 4:59 pm |
Parse error: parse error, unexpected ‘}’ in C:\wamp\www\wordpress\wp-content\plugins\page-restriction.php on line 160
January 30th, 2007 at 11:13 am |
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.
January 30th, 2007 at 12:18 pm |
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!
February 2nd, 2007 at 8:35 am |
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
February 4th, 2007 at 1:13 pm |
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.
February 6th, 2007 at 9:29 pm |
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
February 7th, 2007 at 3:47 pm |
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
February 27th, 2007 at 2:19 pm |
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?
March 16th, 2007 at 10:08 am |
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…..
March 16th, 2007 at 3:13 pm |
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.
March 17th, 2007 at 2:23 pm |
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.
March 23rd, 2007 at 5:51 pm |
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?
April 20th, 2007 at 7:08 am |
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.
April 27th, 2007 at 10:49 am |
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!
June 11th, 2007 at 2:05 pm |
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
June 12th, 2007 at 11:30 am |
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
June 13th, 2007 at 4:59 pm |
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. >_
June 26th, 2007 at 8:13 pm |
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
June 29th, 2007 at 2:58 pm |
on the latest WP the plugin won’t activate
Plugin could not be activated because it triggered a fatal error.
July 8th, 2007 at 2:03 am |
graeme, are u planning to make ur version available?
July 9th, 2007 at 10:21 pm |
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.
July 12th, 2007 at 10:07 pm |
[…] “Page Restriction” - works nicely with “Page Access” (which implements a proprietary Roles system). […]
July 15th, 2007 at 10:23 am |
I get this message under Options/Page Restrictions:
No pages yet.
Why is it not recognizing my pages?!
July 15th, 2007 at 11:04 am |
Thanks Graeme
I haven’t upgraded to WP 2.2+ yet but once I do I’ll be sure to use your plugin.
July 16th, 2007 at 6:16 am |
I don’t understand how it works! I uploaded it to my plugins folder, what now??? Please, HELP!
July 16th, 2007 at 7:01 am |
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?
August 19th, 2007 at 8:06 am |
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
September 6th, 2007 at 11:02 am |
I have just installed your plugin on a new blog I am doing and first - thank you!
October 18th, 2007 at 11:53 am |
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
October 25th, 2007 at 9:16 pm |
I am also getting the message, no pages yet.
I am running WP 2.2.
Help and advice much appreciated. Thank you
November 8th, 2007 at 3:24 pm |
There’s a small bug in line 115 in v. 1.4
-
November 13th, 2007 at 2:19 am |
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 [
December 12th, 2007 at 11:55 am |
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
January 10th, 2008 at 11:39 am |
This guy has fixed both this plugin and Page Access for WP2.3.2
I’m using it now.
http://bytor.co.uk/library
January 10th, 2008 at 11:44 am |
just kidding, the page restrictions won’t stick.
January 16th, 2008 at 5:20 am |
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?
January 22nd, 2008 at 8:15 am |
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?
January 27th, 2008 at 3:02 am |
I installed it but don’t know how to use. Please help.
January 28th, 2008 at 8:52 am |
Same problem with everyone.”No pages yet.!!” Is there anyone who solve this problem? Please share us your solution about this problem.
March 2nd, 2008 at 4:47 pm |
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.
March 11th, 2008 at 1:01 am |
[…] 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. […]
March 18th, 2008 at 9:20 pm |
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???
April 29th, 2008 at 7:04 pm |
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.
May 6th, 2008 at 2:41 am |
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?