WordPress XML-RPC Patch For metWeblog newPost() Method

I have been doing some work with the XML-RPC functionality of WordPress and ran into a problem with the metWeblog.newPost() method. The problem? If you try to post a dateCreated value you actually get an error. At first I thought it was the format of the date/time that I was trying to post. So of course I tried about a googolplex combinations of formats, but always received the same error.

My next step was to investigate the code and find the line that was throwing the error. When I found the line of code the problem was only too obvious. The code block that caused the problem is as follows:

Do you see the problem? No? The first line retrieves the dateCreated value that you passed into the method. This is a string. If the string is not empty then the next line (inside the if) calls the getIso() method on it… on a string. See the problem now? A quick search through the WordPress code found the getIso() method inside the IXR_Date class. This is obviously what they were going for so I just needed to cast our string date to an IXR_Date and that should fix it. This gave me the following:

A quick run of my test program confirmed that the solution was valid. So if you are using WordPress and would like to call the metaWeblog.newPost() method with a dateCreated value you can just modify your xmlrpc.php file with the code from above. Don’t want to search in the code? Oh, alright. Here are two patch files to help you out. One is for WordPress 2.1 and the other is for WordPress 2.2. To apply them just navigate to your WordPress installation directory. You should see the xmlrpc.php file. Upload/copy/whatever the patch file to this directory then issue this command:

patch -p0 < xmlrpc.2.x.patch

The x should be either 1 or 2 depending on the version of the patch you downloaded. Enjoy! 🙂

Patch For WordPress 2.1

Patch For WordPress 2.2

  • I tried your fix on wp 2.1.3 and I got a date of 12/31/1969


  • I noticed that I get that date whenever the parsing fails. I think the system just populates that as the default, which is probably just the earliest date that the system can use. What format is your date string in?

    I’m currently passing dates in the format of “20070715T18:34:00” and those work fine.

  • Hi,
    I used the four different formats that are in the wp tables. I did not alter them before sending them.

    One thing, does not the receiving wp site need to have this fix in the xmlrpc.php?

    thank you for the format, I will try that next time!


  • Hi,
    I just posted some of my code in this blog message.



  • I’ve submitted a patch for this as part of ticket 6612 ( http://trac.wordpress.org/ticket/6612 ).

  • Cool. Thanks a lot!

  • I should have asked about this sooner. What I suspect has happened is that you sent the date as a string type instead of using dateTime.iso8601. I’ve heard back from some of the blog clients and they haven’t had any problems using dateCreated. Can you confirm if this is the case?

    For now I’m closing the ticket (http://trac.wordpress.org/ticket/6612) as invalid. If something else comes up indicating there is a problem we can always re-open it.

  • You know you are absolutely correct. The method I was using was pre-formatting the date/time and passing it through as a string. All I had to do was pass it an actual Date object and the XML-RPC (Redstone) library converted it to a dateTime.iso8601 properly.

    Thanks for catching that!

  • Hi Jonathan
    I’m running in this problem too.
    I have just downloaded WP 2.6.2 but I can see a similiar error over there:

    the code:
    if ( !empty( $content_struct[‘date_created_gmt’] ) )
    $dateCreated = str_replace( ‘Z’, ”, $content_struct[‘date_created_gmt’]->getIso() ) . ‘Z’; // We know this is supposed to be GMT, so we’re going to slap that Z on there by force
    elseif ( !empty( $content_struct[‘dateCreated’]) )
    $dateCreated = $content_struct[‘dateCreated’]->getIso();

    $content_struct[‘date_created_gmt’] and $content_struct[‘dateCreated’] are not objects, just strings!

    for me the main problem is that I’m running WP directly on wordpress.com so I can’t fix it.

    how comes that after a year the code was rewritten but the bug is still there???

  • Pingback: bug: wordpress xmlrpc createDate « dam’s blog()

  • @Damiano –

    Please go back and read my comment. The dateCreated and date_created_gmt values are NOT STRINGS. Their type is dateTime.iso8601. This is not a bug in WordPress.

  • Timothy

    I can’t find the code block I need to fix in WP 3.2.1 in the xmlrpc.php. is it anwhere else? Is the dateCreated problem fixed now in WP3?
    If dateCreated is empty it succes:(