I need a specific node type to automatically unpublish 3 months after publishing, but the date of unpublishing needs to remain constant even if the user unpublishes and republishes the node, unless the date is passed in which case it should start again.

Whenever the timer is reset a notice should be sent to the admins, and the date of scheduled unpublishing should be editable by the admins.

Needless to say this is too complex for any current modules, and when I think of writing a module to do it I don't know how to use the drupal api to schedule things with cron, or how to create an administration settings interface to handle the unpublish dates.


Drupal Scheduler will provide the proper infrastructure. Then in a hook_form_FORM_ID_alter(), you can set the date as follows:

global $user;
$roles = $user->roles;

$plusThreeMonths = date("Y-m-d H:i:s", strtotime("+3 months"));
$form['scheduler_settings']['unpublish_on']['#default_value'] = $plusThreeMonths;
// Disable setting of unpublished date unless admin or user 1
if ($user->uid != 1 && !in_array('administrator', $roles)) {
  $form['scheduler_settings']['unpublish_on']['#disabled'] = TRUE;
  $form['field_package_winning_bid']['#disabled'] = TRUE;

Then if you need to update the unpublish date, you can use a function similar to the following:

function _republish_node($nid, $time) {
  $node = node_load($nid);
  // Add time to the publish date
  $unpub = date("Y-m-d H:i:s", strtotime($time));  // pass in a string like "+2 weeks"
  $node->unpublish_on = strtotime($unpub);
  // Set published to true
  $node->status = 1;
  node_save($node);   // Re-save node with updated status
  scheduler_node_update($node); // update publisher fields  
  // Add watchdog or other method to alert admins (or use rules)
  • Ah so I use a custom module to stop the user from messing with the unpublish dates? The lack of permission control on sheduler was the reason I didn't want to use it.
    – J V
    Oct 18 '12 at 9:12
  • Actually the module does come with "Schedule content publication" permission, but there's nothing to lock that date down like you want. Actually I found the module to be very solid and would recommend it.
    – Webdrips
    Oct 18 '12 at 9:19
  • All right, I'll base my module off what you've shown here, thanks!
    – J V
    Oct 18 '12 at 9:25

Checkout the module scheduler, This module allows nodes to be published and unpublished on specified dates. If you want to do any other associated tasks related to publishing and un publish of nodes like sending mails etc can achieve by rules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.