Wordpress: Timezone issue of published field (Atom Publishing Protocol Plugin)

114 views Asked by At

When I post an entry via Atompub API using WordPress Atom Publishing Protocol Plugin (also previous wp-app.php), if the entry includes non-GMT time value as published field like this:

<entry xmlns='http://www.w3.org/2005/Atom'><title type='text'>test</title><content type='text/html'>test</content>
<published>2013-08-27T00:00:00+09:00</published>
<app:control xmlns:app='http://www.w3.org/2007/app'><app:draft>no</app:draft></app:control><category term='test'/></entry>

the timezone (+09:00) is not correctly parsed, and same value (GMT time) is stored into post_date and post_date_gmt field of wp_posts.

post_date: 2013-08-27 00:00:00
post_date_gmt: 2013-08-27 00:00:00
1

There are 1 answers

0
kaorukobo On

Replace get_publish_time() function in wp-content/plugins/atom-publishing-protocol/class-wp-atom-server.php with following code:

/**
 * Retrieve published time to display in XML.
 *
 * @since 2.3.0
 *
 * @param string $published Time string.
 * @return string
 */
function get_publish_time($published) {
    $pubtime = DateTime::createFromFormat(DateTime::RFC3339, $published);

    if (!$pubtime) {
        return array(current_time('mysql'),current_time('mysql',1));
    } else {
        $localtime = $pubtime->format("Y-m-d H:i:s");
        $pubtime->setTimezone( new DateTimeZone('UTC') );
        $gmttime = $pubtime->format("Y-m-d H:i:s");
        return array($localtime, $gmttime);
    }
}

Notice

  • Requires PHP >= 5.2
  • If wp-app.php still exists, the plugin is not used.

Reason

It is because rfc3339_str2time() function in the original implementation drops timezone information.