What is this? From this page you can use the Social Web links to save Restrict authors access to edit comments, the plugin to a social bookmarking site, or the E-mail form to send a link via e-mail.

Social Web

E-mail

E-mail It
July 20, 2007

Restrict authors access to edit comments, the plugin

Posted in: Programmazione

It's my first wordpress plugin, please be kind ;-)

I've noticed that in wordpress (surely 2.2, not tested on previous, so please tell me if it works) there's no capability separation for editing post and comments (on their post). Even using the Role Manager Plugin.

from wordpress codex:

Manage->Comments -- meaning: "show post"-link; "edit post"-, "edit comment"- and "delete comment"-links only on own posts since edit-comment.php (http://trac.wordpress.org/file/trunk/wp-admin/edit-comments.php) looks for "current_user_can('edit_post', $comment->comment_post_ID)"'

I run a lot of multiple authors blogs and sometimes I need only administrators to edit comments (and I'm not the only one).

So I developed this:

PHP:
  1. <?php
  2. /*
  3. Plugin Name: Restrict author access to edit comments
  4. Plugin URI: http://www.laboratoriocaffeina.it/development/2007/07/20/restrict-authors-access-to-edit-comments-the-plugin.html
  5. Description: Block author access to edit comments, leave it only for admin and editors
  6. Version: 0.3
  7. Author: cedmax
  8. Author URI: http://www.dioblog.it
  9. */
  10.  
  11. function check_user_capabilities() {
  12. global $user_level;
  13.  
  14.   if ( ((strpos($_SERVER['SCRIPT_NAME'], 'wp-admin/edit-comments.php')) or (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin/comment.php')))) {
  15.      
  16.      if ($user_level <9){
  17.     echo "<div class='wrap'><h2>Restricted area</h2></div>";
  18.     include('admin-footer.php');
  19.     die();
  20.    
  21.      }
  22.   }
  23. }
  24.  
  25. add_action('init', 'check_user_capabilities');
  26.  
  27. ?>

update
thanks to brad I found out that the direct edit comment link in wordpress points to comments.php and not to edit-comments.php.
so I've changed the script.

update 2
Thanks to Fred (sorry I didn't understand immediatly) and Claus I spotted out another error in version 0.2
Now I've done the v.0.3 changing the hook function: now it works not on the content but on the initialization of the page, so it is not possible for the author to work on comments at all. thanks to everyone :-)

simply download v.0.3, unzip, put the .php file under wp-contents/plugins and activate it from wordpress plugins panel.


Return to: Restrict authors access to edit comments, the plugin