By mysocom on
I want to do simple moderation in my site. I set status Published as Default options for every content type. I want to disable this action for anonymous. Only admin can change content status where owner is anonymous.
Example
authenticated user > create content> page > submit > published
anonymous user > create content> page > submit > unpublished
I tried to change status of the node with hook_nodeapi but it fires for every
Node on the page and after submit too. So in front page with 5 nodes it fires 5 times.
function simple_moderation_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'submit':
if($node->status == 1 && $user->uid == 0) {
$node->status = 0; // UnPublish the node.
break;
}
}
}
Comments
Well yes that is a valid way
Well yes that is a valid way of doing it, and yes the hook would get called every time a node is loaded as well. TBH the performance implications are pretty minor.
Another way would be to use hook_form_alter() to change the value of the "Published" checkbox on the create content page. Perhaps disabling it also.
Or you could set the published status to No by default and give registered users access to the Workflow options so that they can set it to published. However that might mean giving them Administer node permissions which you might not want to do; not sure if this is a good approach.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Maybe It's a right way. But
Maybe It's a right way. But I have a one problem.
after admin publish the node > owner of the node go to this node > it's became unpublished :(
I want this workflow only after submit not view.
function simple_moderation_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
global $user;
switch ($op) {
case 'view':
if ($node->status == 0) {
drupal_set_message(t('This %type was submitted for moderation and will not be accessible to other users until it has been approved.', array('%type' => node_get_types('name', $nodetype))));
}
case 'submit':
if($node->status == 1 && $user->uid == 0) {
$node->status = 0; // UnPublish the node.
break;
}
}
}
In the PHP "switch"
In the PHP "switch" construct, you need a "break;" before the "case 'submit'" clause.
HTH,
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
modr8
One year late... but another option would be to install the nifty modr8 module which will take care of this for you: http://drupal.org/project/modr8
.. prevents posts that are in moderation from showing up in lists, on the /node page, etc., unless the user is the node's author or unless the user has the "administer nodes" or "moderate content" permission. This is NOT an access control module, however, so posts that are in moderation can still be viewed if a user knows the path (URL) corresponding to that post.