#6612 closed defect (bug) (invalid)
Problems with setting XML-RPC date using metWeblog.newPost()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | XML-RPC | Version: | 2.8.4 |
| Severity: | normal | Keywords: | reporter-feedback |
| Cc: | josephscott, westi, effectivemarketing |
Description
Had problems setting a date with newPost and came across this which seemed to fix things. Should this be included as a patch or is there something that we're all missing here?
http://www.franzone.com/2007/07/30/wordpress-xml-rpc-patch-for-metweblog-newpost-method/
Attachments (2)
Change History (11)
comment:1
josephscott — 5 years ago
- Cc josephscott added
- Keywords has-patch added
- Milestone set to 2.6
josephscott — 5 years ago
comment:2
josephscott — 5 years ago
- Milestone 2.6 deleted
- Resolution set to invalid
- Status changed from new to closed
- Version 2.5 deleted
It finally dawned on me what is probably happening here. Instead of sending dateCreated as a dateTime.iso8601, he was probably using the string type.
I've heard back from some of the other blog clients and they haven't had a problem using dateCreated, so I'm closing this as invalid. If further details come up that conclude there is indeed a problem we can always re-open this ticket.
- Resolution invalid deleted
- Status changed from closed to reopened
Reading dateCreated works fine, but you can't set it.
The getIso() method (part of IXR_Date) is being called on a string in 5 different places.
- Cc westi added
- Keywords reporter-feedback added; has-patch removed
Replying to t0mmmmmmm:
Reading dateCreated works fine, but you can't set it.
The getIso() method (part of IXR_Date) is being called on a string in 5 different places.
Please provide an example of a failing request so we can reproduce your issue.
comment:5
josephscott — 4 years ago
- Resolution set to invalid
- Status changed from reopened to closed
Closing this ticket. If the problem turns out to be real and can be reproduced then we'll reopen it.
- Cc effectivemarketing added
- Resolution invalid deleted
- Status changed from closed to reopened
- Version set to 2.8.4
This is tested and is definitely an issue, and I therefore request that the ticket is re-opened.
When enabling error reporting, the following error occurs when using the "metaWeblog.newPost" function:
PHP Fatal error: Call to a member function getIso() on a non-object in /var/www/xmlrpc.php on line 2187
To verify, create the following test file in the same directory as xmlrpc.php:
<?php
include_once('wp-includes/class-IXR.php');
$url = 'http://www.yourdomain.com/xmlrpc.php';
$user = 'admin';
$pass = 'password';
$client = new IXR_Client($url);
$client->query('metaWeblog.newPost', 1, $user, $pass,
array('post_status' => 'draft',
'title' => 'Date Set Test Post',
'description' => 'Test Post',
'dateCreated' => '20090815T10:00:00Z', 1);
$res = $client->getResponse();
if ($res) {
print "Post #$res added successfully<br>\n";
} else {
print "Post not added<br>\n";
}
?>
Obviously change the $url, $user and $pass to your server details.
With an unpatched xmlrpc.php, the above will fail and return "Post not added".
The problem is the following code:
$dateCreated = $content_struct['dateCreated']->getIso();
$content_struct['dateCreated'] is a string, yet an object method is applied.
To fix, simply remove all occurrences of "->getIso()" from xmlrpc.php. When done, the above test code will return "Post #xxx added successfully"
One more issue: in the same section you will find use of the constant GMT:
$post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
However, it is not defined anywhere as a constant and PHP does an implicit conversion. This should be amended to use a string constant instead:
$post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
The enclosed patch corrects xmlrpc.php for both these issues.
Note: The same problem exists in wp_editComment and mw_editPost and have been corrected in the patch, but I have not tested these.
I have also reported this on my site at http://www.effectivemarketingtenerife.com/technical/wordpress-xmlrpc-datecreated-bug-not-fixed/
Your request is incorrectly encoding the date as a <string></string> not an <dateTime.iso8601></dateTime.iso8601> as it should be.
If you encode your request correctly then it will work.
comment:8
in reply to:
↑ 7
effectivemarketing — 4 years ago
- Resolution set to invalid
- Status changed from reopened to closed
Replying to westi:
Your request is incorrectly encoding the date as a <string></string> not an <dateTime.iso8601></dateTime.iso8601> as it should be.
If you encode your request correctly then it will work.
Hi,
Ok, understood.
The corrected code THAT WILL WORK is as follows:
<?php
include_once('wp-includes/class-IXR.php');
$url = 'http://www.yourdomain.com/xmlrpc.php';
$user = 'admin';
$pass = 'password';
$client = new IXR_Client($url);
$date = new IXR_Date('20090815T10:00:00');
$client->query('metaWeblog.newPost', 1, $user, $pass,
array('post_status' => 'draft',
'title' => 'Date Set Test Post',
'description' => 'Test Post',
'dateCreated' => $date), 1);
$res = $client->getResponse();
if ($res) {
print "Post #$res added successfully<br>\n";
} else {
print "Post not added<br>\n";
}
?>
My apologies - however the confusion arises from the Codex (http://codex.wordpress.org/XML-RPC_wp) which isn't very clear.
The codex states (for instance for wp.newPage) that the format for the dateCreate parameter is:
datetime dateCreate
So when reading this there wasn't sufficient information to understand the datetime itself had to be encapsulated in <dateTime.iso8601></dateTime.iso8601> before it would work.
Also, there is very little documentation about the IXR_Client library which makes it a bit more difficult to find the relevant information. I guess I would have reached the correct conclusion earlier if I had built the XML file from scratch rather than using the IXR_Client class.
Ticket can be closed; the above code works perfectly.
comment:9
josephscott — 4 years ago
The IXR library came from - http://scripts.incutio.com/xmlrpc/ - which has details on how to use it. The XML-RPC spec is also a helpful read - http://www.xmlrpc.com/spec - it's fairly short and to the point. The spec describes the XML markup for each data type.

I'm amazed that we haven't had blog clients complaining about this. I've put together a patch to address metaWeblog.newPost and metaWeblog.editPost. Date/time is a very sensitive issue with the current blog APIs, so I'm requesting additional feedback from the wp-xmlrpc email list as well.