Jared Quinn

IT Consulting :: Design :: Events Management

Set Default Post Date

This plugin originated from a request from lellie on the WordPress Support forum, and a subsequent entry in “Ask JaredQuinn” with a first rough-cut answer. It allows you to change the default date/time that is used when a new post/page is created using plain english words for the modified date, e.g. “next monday 00:01″.

I’ve developed the idea further to produce this “plugin”. It is not really eligible to be called a plugin, because installation does require modification to core WordPress files, but until Hooks can be added for those parts of the code, there are no other options.

Configuration

The default post date can be set using the admin panel under “Options” and “Post Date”.

The string supplied can be any string that the php function strtotime() allows, including:

  • next monday
  • tomorrow 3pm
  • in 1 week

More examples, and full documentation of the strings allowed can be found at:

If no value (or invalid value is specified) the Set Default Post Date plugin will revert to the default of now().

Installation

Place the plugin file into the wp-content/plugins directory and activate it from the Plugins menu on the Administration Panel.

No Hooks exist where I need them for this as of WordPress version 2.0.1, so the following changes however the following changes are suggested.

** MAKE SURE YOU ENABLE THIS PLUGIN BEFORE MAKING THE FOLLOWING CHANGES **

Locate the ‘wp_insert_post’ function in wp-includes/functions-post.php and find the section for post date. In WordPress 2.0.1 it looks like:

// If the post date is empty (due to having been new or a draft) and
// status is not 'draft', set date to now
  if (empty($post_date)) {
     if ( 'draft' != $post_status )
         $post_date = current_time('mysql');

and change it so it looks like:

// If the post date is empty (due to having been new or a draft) and
// status is not 'draft', set date to now
if (empty($post_date)) {
   if ( 'draft' != $post_status )
      $post_date = get_default_postdate('mysql');

If you also want to default the display in the ‘edit post’ screen, you can also make the following change.

Find the function named ‘touch_time’ in wp-admin/admin-functions.php and locate the line that, in version 2.0.1 of WordPress looks like:

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

and change it to read:

$time_adj = get_default_postdate('timestamp');

Your done. Now, set the Date String in the Configuration Options and test that your post is dated correctly. Comments/Suggestions etc can be in the Download Page.

Download Set Post Date 0.01a