Make WordPress Core

Changeset 20153


Ignore:
Timestamp:
03/08/2012 11:19:53 AM (13 years ago)
Author:
westi
Message:

XMLRPC: Intoduce a date generation helper method to improve the dates returned over XMLRPC when we have a 0 date stored for drafts.

This improves the ability of clients to work with the new wp Post APIs. See #18429 and #19733 props maxcutler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r20137 r20153  
    517517
    518518    /**
     519     * Convert a WordPress date string to an IXR_Date object.
     520     *
     521     * @access protected
     522     *
     523     * @param $date
     524     * @return IXR_Date
     525     */
     526    protected function _convert_date( $date ) {
     527        if ( $date === '0000-00-00 00:00:00' ) {
     528            return new IXR_Date( '00000000T00:00:00Z' );
     529        }
     530        return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) );
     531    }
     532
     533    /**
    519534     * Prepares post data for return in an XML-RPC object.
    520535     *
     
    527542    protected function _prepare_post( $post, $fields ) {
    528543        // holds the data for this post. built up based on $fields
    529         $_post = array( 'post_id' => $post['ID'] );
     544        $_post = array( 'post_id' => strval( $post['ID'] ) );
    530545
    531546        // prepare common post fields
    532547        $post_fields = array(
    533548            'post_title'        => $post['post_title'],
    534             'post_date'         => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ) ),
    535             'post_date_gmt'     => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false ) ),
    536             'post_modified'     => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_modified'], false ) ),
    537             'post_modified_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_modified_gmt'], false ) ),
     549            'post_date'         => $this->_convert_date( $post['post_date'] ),
     550            'post_date_gmt'     => $this->_convert_date( $post['post_date_gmt'] ),
     551            'post_modified'     => $this->_convert_date( $post['post_modified'] ),
     552            'post_modified_gmt' => $this->_convert_date( $post['post_modified_gmt'] ),
    538553            'post_status'       => $post['post_status'],
    539554            'post_type'         => $post['post_type'],
     
    930945
    931946        // convert the date field back to IXR form
    932         $post['post_date'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ) );
     947        $post['post_date'] = $this->_convert_date( $post['post_date'] );
    933948
    934949        // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
     
    937952            unset( $post['post_date_gmt'] );
    938953        else
    939             $post['post_date_gmt'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false ) );
     954            $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
    940955
    941956        $this->escape( $post );
Note: See TracChangeset for help on using the changeset viewer.