Jared Quinn

IT Consulting :: Design :: Events Management

Ask JaredQuinn
Auto Setting the Timestamp in WordPress

How can I automatically set all posts to 00:01am for the following Monday morning?

(Modified version of a question I answered in the WordPress support forums at http://wordpress.org/support/topic/59803)

This is something that I quickly hacked together. I’ve never actually tried plugging anything into the Admin interface to over-ride/replace anything, so for the moment it’ll stay as a quick hack.

Open up and Edit wp-admin/admin-functions.php, we’re going to put a new function in there.

function get_next_week($tint) {
   $weekdayid = date(“w”, $tint);
   $startoftoday=mktime(0,1,0,date(“n”, $tint), date(“j”, $tint), date(“Y”, $tint));
   return $startoftoday + ((8 - $weekdayid) * 86400);
}

Now, Find the ‘touch_time’ function and in particular the line that says:

$time_adj = time() + (get_settings(‘gmt_offset’) * 3600);

Change it so that it looks like:

// $time_adj = time() + (get_settings(’gmt_offset’) * 3600);
$time_adj = get_next_week(time());

This will cause all posts to default to 00:01 on the following monday. If you want to change that particular date/time, play with the get_ext_week function defined above.





3 Comments

  • lellie

    Hey, I’ve just tried to implement this but it’s going a week ahead of itself.. any ideas? It’s saying 13th feb, when it should say the 6th today.. Something to do with server times? or thinking sunday is the start of the week perhaps?

  • Jared Quinn

    We may have to add some timezone support to it perhaps?

    I’ll work on developing the concept a little further later, and possibly even work it into more of a ‘plugin’.

  • Jared Quinn

    Plugin has been developed much further, follow the link to the next post which is the plugin release announcement.

Leave a Reply