fix the xmlrpc.php for allowing scheduled posts, see http://wordpress.org/support/topic/330597?replies=2
Hello,
I created a tool to manage a huge amount of blogs. This tool should also be able to scedule Postings. I saw that the metaWeblog.newPost command has the fields 'dateCreated' and 'date_created_gmt'. If i assign a Date to it, i get no response from the xmlrpc.php. I figured out that it might be an error at the following code:
starting at line 2183:
// Do some timestamp voodoo
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['dateCreated'] and $content_struct['date_created_gmt'] are NOT objects, they are just an sting, so the call of ->getIso() fails.
I removed the ->getIso() and the Post will be storred at database, but not marked as sceduled. It will be posted, with a date in future... how to fix it.
Or short: How i can scedule a Post using XMLRPC / metaWeblog.newPost
I hope anyone of u can help me solve this Problem. I dont want do store future posts at a database and post it by a cronjob.
greetings
Alexander Kurtz
I found a way to solve my problem, but i had to fix the xmlrpc.php, thats a thing i wount do, because i have to fix it at more than 250 worpressinstallations :( .
I fixed at the Mothod: mw_newPost($args), starting at line 2007
1st fix: starting at line 2105
if( isset( $content_struct["{$post_type}_status"] ) ) {
switch( $content_struct["{$post_type}_status"] ) {
case 'draft':
case 'private':
case 'publish':
case 'future': # <-- ADDED THIS LINE
$post_status = $content_struct["{$post_type}_status"];
break;
case 'pending':
// Pending is only valid for posts, not pages.
if( $post_type === 'post' ) {
$post_status = $content_struct["{$post_type}_status"];
}
break;
default:
$post_status = $publish ? 'publish' : 'draft';
break;
}
}
2nd fix: starting at line 2203
remove the call off non existing Method ->getIso()
// Do some timestamp voodoo
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()*/;
}
In my code i add 2 fields $content-array if its in future:
if (strtotime($_REQUEST['form']['dateCreated']) > time()) {
$content['post_status'] = 'future';
$publish = 0;
}
so my XML will look like:
<methodCall>
<methodName>metaWeblog.newPost</methodName>
<params>
<param>
<value>
<array>
<data>
<value>USERNAME
<string></string>
</value>USERNAME
<value>
<string>{YOUR-WP-USERNAME-HERE}</string>
</value>
<value>
<string>{YOUR-WP-PASSWORD-HERE}</string>
</value>
<value>
<struct>
<member>
<name>wp_slug</name>
<value>
<string></string>
</value>
</member>
<member>
<name>wp_password</name>
<value>USERNAME
<string></string>
</value>
</member>
<member>
<name>wp_author_id</name>
<value>
<string></string>
</value>
</member>
<member>
<name>title</name>
USERNAME
<value>
<string>Test of sceduled Posting</string>USERNAME
</value>
</member>
<member>
<name>description</name>
<value>
<string><p>Test of sceduled Posting</p></string>
</value>
</member>
<member>
<name>mt_excerpt</name>
<value>
<string><p>Test of sceduled Posting</p></string>
</value>
</member>
<member>USERNAME
<name>mt_text_more</name>
<value>
<string></string>
</value>USERNAME
</member>
<member>
<name>mt_allow_comments</name>
<value>
<string></string>
</value>
</member>
<member>
<name>mt_allow_pings</name>
<value>
<string></string>USERNAME
</value>
</member>USERNAME
<member>
<name>date_created_gmt</name>
<value>
<string>2009-12-11 13:00:00</string>
</value>
</member>
<member>
<name>post_status</name>
<value>USERNAME
<string>future</string>
</value>
</member>
</struct>
</value>
<value>
<int>0</int>
</value>
</data>
</array>
</value>
</param>USERNAME
</params>
</methodCall>
greetings
Alexander Kurtz