Allow Categories

Ok, latest wordpress plugin modification. This time its of L. Fargue’s Restrict categories plugin.

  • Users are assigned permissions to view posts in certain categories
  • If users don’t have permission to certain posts, those posts aren’t shown, including in the main view and archives.
  • Categories can be made public to everyone, and there is an option to force users to login.
  • This is an initial version, so please report any errors or bugs.

Installation:
1) Download the plugin: http://wordpress.org/extend/plugins/allow-categories/
2) Unzip it
3) Copy to your wp-content/plugins directory
4) Activate within wordpress admin
5) Goto Managed->Allow Categories to edit permissions

Change Log:
0.6.4
Removed debug statement
0.6.3
Fix for recent posts
0.6.2
Remove debug statement
0.6.1
Added allow_list_categories($args) function that can be used in templates to replace wp_list_categories($args) functions. This is a work around until wordpress provide a proper hook for filter a list of categories, so its not perfect. It may work in place of some wp_list_cats() and list_cats() too.
0.6.0
Fix for (Public) posts and redirect to login
Admin users no longer show up in list for version 2.5+
0.5.9
Option to redirect to login if viewing a post or category that is not public and the user is not already logged in
0.5.8
Small bug fix to comment logic in 0.5.6
0.5.7
Allows editing of draft posts by non-admin owner of the draft.
0.5.6
Shows comment content for RSS for public posts or for RSS readers that
know that share login information with the browser (eg. Opera).
0.5.5
Bug fix that would show posts to users who had no categories listed.

Disclaimer:
This plugin is experimental and is provided with no support or warranty. It should not be considered as providing complete security to wordpress content.


Reader Comments

  1. Peter, not sure about that problem, I haven’t seen anything similar, when I get time I’ll test.

    Chris, that feature has been requested before, its on my todo list, I’ll get round to it when I have time.

    Peace,
    James

  2. @Flak,
    I did some very simple testing with WP2.5 and it seemed to work (AC 0.5.4), can you elaborate on what you think did not not work with WP2.5.

  3. @Flak

    I’m using the bleeding edge (2.6) and the plugin seems to be working like it should or I haven’t gotten any issues.

  4. installed version 0.5.4 on wp 2.2.3. defined 2 categories and 2 users. each user was given access to 1 category. when i go to the site home page i get the following error:

    Warning: implode() [function.implode]: Invalid arguments passed in /home/bigmoxy/public_html/wp223/wp-content/plugins/allow-categories/allowcat.php on line 133

    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 ‘->posts p, $wpdb->post2cat p2c, $wpdb->categories c WHERE p.ID = p2c.post_id AND’ at line 1]
    SELECT p.ID FROM $wpdb->posts p, $wpdb->post2cat p2c, $wpdb->categories c WHERE p.ID = p2c.post_id AND p2c.category_id = c.cat_ID AND category_id in ();

  5. Hello,

    I’ve encountered a problem with your plugin version 0.5.4 on WordPress 2.3.3 – when it’s enabled I cannot get new categories to work and I cannot access posts autosaved as drafts. I can’t even find those posts on the “manage – posts” page and if I try to access them via the “write post” page, I encounter 404 errors. When I deactivate your plugin, everything works again!

    What can I do?

  6. P.S.: Okay, I figured out that I first need to set the new category accessible for admin. D’OH. But what about the auto-saved drafts?

  7. Hi, i found your plugin as an alternative to David Coppits ‘Category Access’ solution (http://www.coppit.org/code), that – although it claims to be wp 2.3-compatible, really isn’t completely.

    Maybe you can still have a look at this plugin, as it uses a standard way to not only hide posts, but also elements from the category tree…

    Great work!
    Best regards

  8. I’m afraid it’s me again with another usage question … I have a category that is supposed to be visible only to users who are logged in. In the RSS, the post itself does not show up, but the comments do. If I check “forced login”, will that prevent that from happening? Or do I need to change something in my comments files (I’m using Brian’s Threaded Comments)? There’s probably a very simple solution and I’m just too dumb to see it. I’d be grateful for any help!

  9. @Tim: There is a fix for your problem in the latest version.

    Juno: I’m not sure how Brian’s Thread Comments will affect things, but if you’re not logged in, then the content of comments should be blanked out. Though the fact that there is a comment should still appear in the RSS feed so people can be notified of new comments. If you force loggin though, and leave “Do not force login for feed” unchecked then no comments will appear in your feed.

  10. (WP2.5.1) When I set a category to “(Public)” with “Redirect to logon if not permissioned” turned on, unauthenticated users are still being redirected. If I set “Redirect to logon…” off, they get access to the permitted categories and the “not found” behaviour for unauthorized categories. Any ideas?

  11. Found it (I think)! In line 306, I changed “$keep = false;” to “$redirect = false;” and now it seems to work fine.

  12. Hi James,

    Nice plugin, I’ve been using it for a few months on a semi-private blog and it does the job quite well.

    The only thing I’ve noticed is that it doesn’t seem to work with “fancy” permalinks.

    Would be great to also add pages also.

    Thanks,
    Gene

  13. LOL, let me rephrase the last sentence.

    It would be great to be able to add “allowed pages” too.

    Gene

  14. Sorry, theme related…

    I can see your point about adding pages, I’ll try to find a plugin that will hide certain pages till logged in (better than nothing…LOL!).

    Cheers,
    Gene

  15. What’s the best way to exclude not-allowed categories from search results? Has anyone combined Allow Categories with one of the search plugins?

  16. I love your Allow Categories plugin. So simple and to the point. I am using a WP install as a project review site for customers, so it is exactly what I needed. I am now in search of an extension to your plugin that will only show categories in the sidebar that the user has access to. (Lets say client A has projects 1, 2 & 3, then I would like them to be able to see their different project categories) Any thoughts about how to do this? or if it would be hard?

  17. Hi thanks for your interest. I have thought about this, but wordpress currently provides no convenient place for plugins to determine which categories are listed. It currently only has a place where you can filter the outputted HTML, which is a messy place to do it, as different templates use different HTML to list categories. If wordpress expand the API I will change it so that this is done automatically.

    I have come up with a work around in the latest version (0.6.1). If you can edit your theme, you can replace any wp_list_categories() list_cats or wp_list_cats with allow_list_categories().

  18. No matter what I do, if I am logged in or out, the content of comments posted to un-allowed posts show up in the RSS feed reader. Do you have any idea at what I have to look in order to fix that?

  19. Just installed and works good, I had to change the category display function to allow_list_categories() to make this hide the categories, works a treat, thanks for the great plugin.

  20. I installed 0.6.1 version, works pretty much in the way that I expected, but if I click the archives page, post titles belonging to my restricted category are listed, if you click any of those titles instead of being redirected to the login page I got the error message posted below. If I click the category name of this restricted page I’m being redirected to login page.

    Array ( [0] => 6 [1] => 7 [2] => 5 )
    Warning: Cannot modify header information – headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\plugins\allow-categories\allowcat.php:334) in C:\xampplite\htdocs\wordpress\wp-content\plugins\allow-categories\allowcat.php on line 355

    Warning: Cannot modify header information – headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\plugins\allow-categories\allowcat.php:334) in C:\xampplite\htdocs\wordpress\wp-content\plugins\allow-categories\allowcat.php on line 356

    Warning: Cannot modify header information – headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\plugins\allow-categories\allowcat.php:334) in C:\xampplite\htdocs\wordpress\wp-content\plugins\allow-categories\allowcat.php on line 357

  21. Hi, thanx for this neat plugin.

    Do you think that it’s possible to add another function for replacement of wp_list_pages()? – I have some pages that have “invisible” categories and I want to hide them in the main-menu of the template – but the template uses wp_list_pages for displaying…

    Thanx in advance,

    Michael

  22. Sorry I’m not quite sure what feature you’re asking for. So are you saying you’re not able to change the template at all to change the function or you want additional functionality?

  23. Hello,

    I love this simple little plug-in. I’m wondering if there is a way to make it so that an RSS feed displays all posts regardless of whether it is allowed or not. It would be even better if I could customize the URL so it’s a bit more hidden.

    For instance, all posts are hidden except if they are added to a “Public” category. Even if my users are logged into WordPress, if they add the Feed to iGoogle for instance, iGoogle only displays the Public posts. I’d like it to display all of them on the feed.

    Ideas?

  24. Thanks for this plugin!

    When logged in, whenever you click a public post you get this error message on top of the page;

    Array ( [0] => 1 [1] => 4 [2] => 3 [3] => 6 [4] => 7 [5] => 5 )

  25. great plugin but I can only set 13 categories and I hve 40. Is there a way to get to my other categories? also it would be great to have a place to set all categories for a user at one time without checking every box. Last request would be an option to allow all registered users to see everything and visitors to see only selected categories….thanks…Jim

  26. I have a version where there is an “echo query” on line 153 into the file allowcat.php, who needs to be commented to avoid an Array() line to be displayed on the top of the website when we read an article. ^^

  27. Hi James,
    Great plugin – it adds something which I really need. However, whilst investigating browser compatibility (a problem with IE – yes, really) I encountered an iPhone difficulty. With Allow Categories activated the front page on my 3G iPhone shows ‘Sorry no posts match your criteria’.
    This seems only to happen with the iPhone. If I de-activate Allow Categories the site behaves itself. I will investigate further but in the meantime, any ideas?

  28. Hi James,
    the problem I mentioned occurs even if Allow Categories is the only activated plugin.
    I’m using WP 2.6.5
    Thanks,
    Brian

  29. Thanks for your great job!
    And could any one tell where to download the version 0.6.2? The link of wordpress.org is still 0.6.1.

  30. Hi
    Thanks for this wonderful plugin!!

    I noticed that “Recent Posts” listing was showing all posts , I added
    add_filter(‘getarchives_where’, array(‘Allow_Category’,’allow_where’));
    in the plugin file, and apparently it’s working now.

  31. Pingback: Allow Categories

Write a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.