Admin's node set to published by default?
Question
I currently have nodes set to unpublished by default because I want to approve user submitted content before publishing it live. However, admins should have their nodes published by default. How can I accomplish this?
Solution
Assuming Drupal 6.
Define a hook_form_alter function in your custom module and set the '#default_value' of the status element to TRUE. This will only run if the user has the correct permission. This way, nodes can also be unpublished by unticking the 'Published' checkbox.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if (user_access('administer nodes')) { // or other permission
$form['options']['status']['#default_value'] = TRUE;
}
}
Now your admin's nodes will be automatically published.
Thanks to andy for his comments.
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange