ページ

2014年7月29日火曜日

WordPress blogger_newPost() に投稿日時を指定する。

WordPressへ外部から投稿を可能にする、 blogger_newPost() ですが、
投稿日時をMySQLのシステム日時から自動で取得します。

過去記事を外部投稿したい場合、これでは不都合です。

投稿日時を指定できるように改良していました。

class-wp-xmlrpc-server.php から抜粋


/**
* Create new post.
*
* @since 1.5.0
*
* @param array $args Method parameters.
* @return int
*/
function blogger_newPost($args) {

$this->escape($args);

$blog_ID    = (int) $args[1]; /* though we don't use it yet */
$username = $args[2];
$password  = $args[3];
$content    = $args[4];
$publish    = $args[5];

if ( !$user = $this->login($username, $password) )
return $this->error;

/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'blogger.newPost' );

$cap = ($publish) ? 'publish_posts' : 'edit_posts';
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || !current_user_can($cap) )
return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.'));

$post_status = ($publish) ? 'publish' : 'draft';

$post_author = $user->ID;

$post_title = xmlrpc_getposttitle($content);
$post_category = xmlrpc_getpostcategory($content);
$post_content = xmlrpc_removepostdata($content);

$post_date = current_time('mysql');
$post_date_gmt = current_time('mysql', 1);
/* args[6] に投稿日時を追加 K.Katagiri */
if($args[6]){
$post_date = args[6];
$post_date_gmt = args[6];
}

$post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');

$post_ID = wp_insert_post($post_data);
if ( is_wp_error( $post_ID ) )
return new IXR_Error(500, $post_ID->get_error_message());

if ( !$post_ID )
return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));

$this->attach_uploads( $post_ID, $post_content );

/**
* Fires after a new post has been successfully created via the XML-RPC Blogger API.
*
* @since 3.4.0
*
* @param int   $post_ID ID of the new post.
* @param array $args    An array of new post arguments.
*/
do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args );

return $post_ID;
}

0 件のコメント:

コメントを投稿