Allow users with a certain role to post without moderation

Drupal 5.x version of: http://drupal.org/node/113696

Using the 4.x code from the link above I created a mini module and decided to name it 'moderation_skip'. Perhaps a more accurate name would be 'auto-publish' or something like that, but you get the idea.

1. Create a directory under modules named moderation_skip.

2. Put the following in moderation_skip.module:

<?php

/**
* Implementation of hook_perm().
*/
function moderation_skip_perm() {
  return array(
'skip node moderation');
}

/**
* Implementation of hook_nodeapi()
*
* Set the moderation state of a node
*/
function moderation_skip_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch (
$op) {
    case
'submit':
      if (
$node->status != 1 && user_access('skip node moderation')) {
         if (!
user_access('administer nodes')) { // Don't reset for admins
           
$node->status = 1; // Publish the node.
        
}
      }
      break;
  }
}

?>

3. Put the following in moderation_skip.info:

name = Moderation skip
description = "Allow users with certain roles to bypass node moderation."
version = "5.x-0.1"

4. Visit modules admin page and enable the new module.

5. Visit role permissions and grant the 'skip node moderation' permission to any roles required.

how about 6.x?

xcorex - April 7, 2008 - 07:10

It works?

Drupal 6.x modifications...

Shnapoo - April 27, 2008 - 11:03

For Drupal 6.x (untested):

Moderation_skip.info file must look like:

; $Id$
name = Moderation skip
description = "Allow users with certain roles to bypass node moderation."
core = 6.x

Moderation_skip.module file must look like:

<?php
/**
* Implementation of hook_perm().
*/
function moderation_skip_perm() {
  return array(
'skip node moderation');
}

/**
* Implementation of hook_nodeapi()
*
* Set the moderation state of a node
*/
function moderation_skip_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch (
$op) {
    case
'presave':
      if (
$node->status != 1 && user_access('skip node moderation')) {
         if (!
user_access('administer nodes')) { // Don't reset for admins
           
$node->status = 1; // Publish the node.
        
}
      }
      break;
  }
}
?>

Remove the ?> at the end, so it won't break your HTTP headers!

Somebody should verify the code and create a new book page at the right section.

I don't understand the

esllou - June 24, 2008 - 16:57

I don't understand the "don't reset for admins" part of the snippet. I have this module set up and it seems to be fine except for uid 1, the main admin, whose every node goes into moderation. That can't be right...shouldn't it be the other way around?

Please excuse if I forward you...

Shnapoo - July 17, 2008 - 12:30

...to http://drupal.org/node/113696 for a description of the module.

 
 

Drupal is a registered trademark of Dries Buytaert.