WP Block Admin

This is a simple plugin which blocks access to the admin interface based on a user’s capabilities (permissions).

See the plugin info on wordpress.org.

If you have any support questions, please fire them here as a comment.

32 Comments

  1. Scot MacDonald
    Posted 11 Feb 2009 at 06:44 | Permalink

    Callum

    I realize you don’t support this plugin but I thought I’d drop a note in the event you could see an obvious issue. I’m using block Admin with WPMU and Buddypress and I’m trying to keep users from seeing the WP backend. I’ve tried your plugin (I actually thought I had it working for awhile) but users are still getting access after logging in and trying the URL/wp-admin link.

    I’m also using a custom plugin that redirects people logging in to go to their member page in Buddypress versus the backend. Not sure if this is conflicting, but I don’t think so.

    Appreciate your thoughts…

    Thx

    • Posted 11 Feb 2009 at 07:25 | Permalink

      @Scot MacDonald: Hey Scot, nice surname! :)

      My guess is that you’re seeing problems because your users are admins on the blog. Somebody else recently asked me about a WPMU version related to buddyPress and I modified the plugin slightly for them. It seemed to work well. I’ve added that code to the plugin but commented it out. Version 0.1.2 should appear on wp.org in an hour or two, when that does, look at line 37 and you should be able to make it work for WPMU quite easily. Just comment out line 36 and uncomment line 38.

  2. Posted 11 Feb 2009 at 08:37 | Permalink

    hi. Thanks for plugin

    perfect.

    Regards

  3. Scot
    Posted 11 Feb 2009 at 10:08 | Permalink

    Callum

    Thanks for the input. Looking forward to trying the new code.

    As it turns out though, I have my new users defaulted to Author. I’ve tried using the plugin with both new ‘members’ and new ‘blogs’ and it still isn’t working right. I’ve removed the other plugin that had the redirect and still no go. One thing I have noticed is that providing a redirect URL is definitely not working as users are always taken to the homepage regardless of what I use. All of this said, there are cache issues with Buddypress as well so maybe that’s part of the problem as well. Makes it challenging to test I must say.

    I know a lot of Buddypress users are looking for a way to hide the admin area as it is very confusing for users who have the BP profile and then find themselves behind the wall in the admin section with another profile.

    Cheers

    ps – I’m from Atlantic Canada and was in Edinburgh last year. Spent some time at The Last Drop. :)

    • Posted 11 Feb 2009 at 10:29 | Permalink

      @Scot: I’m not sure what’s going on with buddyPress. This plugin is called as early as possible in the WP boot up, so at a guess I’d say it would work with a caching plugin (I haven’t looked into it).

      To aid debugging, try adding some exit(’message’); calls to the plugin. That will help you to see if it’s being called.

  4. Posted 09 Apr 2009 at 15:19 | Permalink

    Hey Callum,

    Your plugin does exactly what I was looking for. I installed it and found that it wasn’t working for some reason. After looking at the code, I saw the problem:

    if (strpos(strtolower($_SERVER['REQUEST_URI']),’/wp-admin/’)) {

    should be

    if (strpos(strtolower($_SERVER['REQUEST_URI']),’/wp-admin/’) !== false) {

    Since the strpos() of ‘/wp-admin/’ can return zero, the value needs to be evaluated as not equal to false; otherwise, the user’s access level is never checked for blogs that are installed on the root of a domain.

    Thanks for the plugin!

    • Posted 09 Apr 2009 at 16:09 | Permalink

      @Jonah Korbes: You are absolutely correct. I routinely make that mistake with strpos. I have added your fix and a note crediting you. Thanks for the fix. :)

  5. Posted 07 May 2009 at 03:04 | Permalink

    Thanks for Plugin. :)

  6. Posted 09 May 2009 at 17:12 | Permalink

    Thanks for that plugin! I just installed it and it worked without having to change anything. Now I’m wondering if you’ve ever thought of removing the “Site Admin” link when it’s deactivated by WP Block Admin :-)

    • Posted 09 May 2009 at 20:03 | Permalink

      @Malcolm: I think you can get rid of that via your theme. It’s part of the Meta widget I believe. Not sure if / how I’d plug into that to remove it. Interesting idea though… :-)

  7. Posted 09 May 2009 at 20:41 | Permalink

    Thanks. If I’d get rid of that link n the theme, I’d want to condition that getting-rid-of on your plugin having deactivated the link (or redirecting it, whatever you do). Can you think of a test I could make?

    • Posted 11 May 2009 at 14:02 | Permalink

      @Malcolm: You could use the same test as in the plugin itself.
      if (!current_user_can($wpba_required_capability))

  8. Posted 11 May 2009 at 14:09 | Permalink

    Thanks! I’ll give that a try and report back.

  9. Posted 11 May 2009 at 14:44 | Permalink

    Yep, that worked after I realized I needed to add the setup for $wpba_required_capability :-) Now the Site Admin link doesn’t appear unless it’s functional.

    Thanks for the help and for the great plugin!

    • Posted 11 May 2009 at 14:53 | Permalink

      Malcolm: I’m surprised you need to setup $wpba_required_capability. Are you calling it within a function maybe? You could try making it global, that might do the trick. I’d guess that all the plugins are loaded (and so $wpba_required_capability is setup) before the theme loop starts, but I might be wrong.

  10. Posted 11 May 2009 at 15:39 | Permalink

    It’s working perfectly now. But here’s the code if you want to take a look:


    < ?php global $wpba_required_capability;
    if (current_user_can($wpba_required_capability))
    wp_register();
    ?>

  11. Posted 11 May 2009 at 15:42 | Permalink

    You can login to the site (http://ca-bankruptcylaw.com) if you want with the following ID and password if you want to see it in action:

    ID: eastmont1 PW: 123

  12. Posted 03 Jun 2009 at 07:55 | Permalink

    Hi Callum,

    Greeeeat plugin,

    But I have some issues with the upload page, every time I send a file the frame with the forms (Legend, Title, Description etc) the iframe redirect to the home. I using de WP 2.7.1 …

    The upload works nice, just this redirect is a little inconvenience…

    Any idea why this happens?

    Thanks!

    • Posted 03 Jun 2009 at 12:45 | Permalink

      @Caciano: Aha. It sounds like that form is in /wp-admin/ even though it is used on the front end. Interesting. Try changing line 51, which is currently:
      if (strpos(strtolower($_SERVER['REQUEST_URI']),'/wp-admin/') !== false) {
      to this:
      if (is_admin()) {

      If that works for you, I’ll probably change the plugin to use that method.

  13. Posted 04 Jun 2009 at 09:05 | Permalink

    Thanks Callum, now it works perfectly!

  14. Posted 12 Jun 2009 at 03:43 | Permalink

    I admit that I have not had a chance yet to look at the code yet (busy morning) but we have been recommending this plugin to users of our forum plugin and with our latest release added the technique as an option. Are you aware that (at least using WP2.8) it disables the use of the flash uploader?

    • Posted 12 Jun 2009 at 10:46 | Permalink

      @andy: Try changing line 51 from:
      if (strpos(strtolower($_SERVER['REQUEST_URI']),'/wp-admin/') !== false) {
      to:
      if (is_admin()) {

      Does that resolve the issues with 2.8? I don’t use the plugin personally so I don’t test it. Are you interested in taking over the maintenance of the code?

      If that change works for you (it worked for somebody else recently), I’ll make the change and push out a new version.

      • Posted 12 Jun 2009 at 12:47 | Permalink

        No – still no luck. Can’t really see why though unless the WP guys have screwed up the capabilities check for image uploading….

  15. Anthony
    Posted 08 Jul 2009 at 13:17 | Permalink

    Hi, is there any way I can use this for WPMU but not completely block my users? I saw your first suggestion but I do not have buddypress so I do need to give my users some access for the standard menus and for some menus that my addons created. Im not sure how the first poster had blogs defaulted to author users but my users are Admins.

    • Posted 08 Jul 2009 at 13:28 | Permalink

      You can use the plugin as a starting point then modify it to your own requirements.

  16. Anthony
    Posted 08 Jul 2009 at 13:31 | Permalink

    Ok, So I switch the commented lines and then what would be a code I would use to add in each capability to block?

    • Posted 01 Nov 2009 at 18:07 | Permalink

      I don’t think I’ve ever replied to your question, apologies.

      If you’re still having the issue, you can edit line 18. It’s clearly marked in the code.

  17. Posted 17 Aug 2009 at 00:07 | Permalink

    Hey there,
    Great plugin!
    I am a bit of a newbie, so don’t want to play around too much in case i break something (i have the horrible wordpress version 2.8 and it’s very tempremental, so much so in fact it won’t let me upgrade!!)
    Anyway, back to the point. Can you please let me know what code I need to put in and where to make this only redirect subscribers? Sorry I have done a bit of googling to try and find the answer to this but there doesn’t seem to be one.
    thanks again! :)

    • Posted 17 Aug 2009 at 13:42 | Permalink

      You want to redirect subscribers but nobody else. Is that correct?

      You can edit line 18 of the plugin. Choose a new capability. Looking at this list, contributors have “edit_posts” and “delete_posts” capabilities while subscribers don’t. I’d guess either of those would work, if I’ve understood what you want correctly. Please share your solution back here for others.

  18. Posted 13 Oct 2009 at 10:04 | Permalink

    THANK YOU!

    I was searching for hours for a plugin like this one!

    I was just looking for the wrong thing, but thanks, now I have it, it works like a charm!

  19. Posted 01 Nov 2009 at 06:08 | Permalink

    Hrmm i’m on 2.9 and still having the same 2.8 issues with the http error upon uploading an image. Substituting is_admin does not fix this problem. Something to do with the wp_redirect?

    • Posted 01 Nov 2009 at 18:05 | Permalink

      I’m not sure what causes the issues with the image uploader. I wrote this plugin for somebody else and haven’t used or tested it since. If you’re able to find the problem and would like to submit a patch, please do. If you’d like to take over the maintenance of the code give me a holler. :-)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Categories

  • History