Expose post format details in XML-RPC:

- New method: wp.getPostFormats
- New field in methods dealing with posts: wp_post_format

props ericmann, fixes #15405



git-svn-id: http://svn.automattic.com/wordpress/trunk@16484 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
josephscott 2010-11-19 13:57:05 +00:00
parent 90a0e069e9
commit 43ff5a69a8
1 changed files with 65 additions and 1 deletions

View File

@ -63,6 +63,7 @@ class wp_xmlrpc_server extends IXR_Server {
'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', 'wp.getCommentStatusList' => 'this:wp_getCommentStatusList',
'wp.getMediaItem' => 'this:wp_getMediaItem', 'wp.getMediaItem' => 'this:wp_getMediaItem',
'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', 'wp.getMediaLibrary' => 'this:wp_getMediaLibrary',
'wp.getPostFormats' => 'this:wp_getPostFormats',
// Blogger API // Blogger API
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
@ -1602,6 +1603,31 @@ class wp_xmlrpc_server extends IXR_Server {
return $attachments_struct; return $attachments_struct;
} }
/**
* Retrives a list of post formats used by the site
*
* @since 3.1
*
* @param array $args Method parameters. Contains:
* - blog_id
* - username
* - password
* @return array
*/
function wp_getPostFormats( $args ) {
$this->escape( $args );
$blog_id = (int) $args[0];
$username = $args[1];
$password = $args[2];
if ( !$user = $this->login( $username, $password ) )
return $this->error;
do_action( 'xmlrpc_call', 'wp.getPostFormats' );
return get_post_format_strings();
}
/* Blogger API functions. /* Blogger API functions.
* specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
*/ */
@ -2083,6 +2109,14 @@ class wp_xmlrpc_server extends IXR_Server {
if ( !current_user_can( $cap ) ) if ( !current_user_can( $cap ) )
return new IXR_Error( 401, $error_message ); return new IXR_Error( 401, $error_message );
// Check for a valid post format if one was given
if ( isset( $content_struct['wp_post_format'] ) ) {
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
return new IXR_Error( 404, __( 'Invalid post format' ) );
}
}
// Let WordPress generate the post_name (slug) unless // Let WordPress generate the post_name (slug) unless
// one has been provided. // one has been provided.
$post_name = ""; $post_name = "";
@ -2267,6 +2301,11 @@ class wp_xmlrpc_server extends IXR_Server {
$this->attach_uploads( $post_ID, $post_content ); $this->attach_uploads( $post_ID, $post_content );
// Handle post formats if assigned, value is validated earlier
// in this function
if ( isset( $content_struct['wp_post_format'] ) )
wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format' );
logIO('O', "Posted ! ID: $post_ID"); logIO('O', "Posted ! ID: $post_ID");
return strval($post_ID); return strval($post_ID);
@ -2358,6 +2397,14 @@ class wp_xmlrpc_server extends IXR_Server {
if ( !current_user_can( $cap ) ) if ( !current_user_can( $cap ) )
return new IXR_Error( 401, $error_message ); return new IXR_Error( 401, $error_message );
// Check for a valid post format if one was given
if ( isset( $content_struct['wp_post_format'] ) ) {
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
return new IXR_Error( 404, __( 'Invalid post format' ) );
}
}
$postdata = wp_get_single_post($post_ID, ARRAY_A); $postdata = wp_get_single_post($post_ID, ARRAY_A);
// If there is no post data for the give post id, stop // If there is no post data for the give post id, stop
@ -2553,6 +2600,11 @@ class wp_xmlrpc_server extends IXR_Server {
$this->attach_uploads( $ID, $post_content ); $this->attach_uploads( $ID, $post_content );
// Handle post formats if assigned, validation is handled
// earlier in this function
if ( isset( $content_struct['wp_post_format'] ) )
wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format' );
logIO('O',"(MW) Edited ! ID: $post_ID"); logIO('O',"(MW) Edited ! ID: $post_ID");
return true; return true;
@ -2620,6 +2672,11 @@ class wp_xmlrpc_server extends IXR_Server {
if ( $postdata['post_status'] === 'future' ) if ( $postdata['post_status'] === 'future' )
$postdata['post_status'] = 'publish'; $postdata['post_status'] = 'publish';
// Get post format
$post_format = get_post_format( $post_ID );
if ( empty( $post_format ) )
$post_format = 'default';
$sticky = false; $sticky = false;
if ( is_sticky( $post_ID ) ) if ( is_sticky( $post_ID ) )
$sticky = true; $sticky = true;
@ -2660,6 +2717,7 @@ class wp_xmlrpc_server extends IXR_Server {
'date_created_gmt' => new IXR_Date($post_date_gmt), 'date_created_gmt' => new IXR_Date($post_date_gmt),
'post_status' => $postdata['post_status'], 'post_status' => $postdata['post_status'],
'custom_fields' => $this->get_custom_fields($post_ID), 'custom_fields' => $this->get_custom_fields($post_ID),
'wp_post_format' => $post_format,
'sticky' => $sticky 'sticky' => $sticky
); );
@ -2741,6 +2799,11 @@ class wp_xmlrpc_server extends IXR_Server {
if ( $entry['post_status'] === 'future' ) if ( $entry['post_status'] === 'future' )
$entry['post_status'] = 'publish'; $entry['post_status'] = 'publish';
// Get post format
$post_format = get_post_format( $entry['ID'] );
if ( empty( $post_format ) )
$post_format = 'default';
$struct[] = array( $struct[] = array(
'dateCreated' => new IXR_Date($post_date), 'dateCreated' => new IXR_Date($post_date),
'userid' => $entry['post_author'], 'userid' => $entry['post_author'],
@ -2763,7 +2826,8 @@ class wp_xmlrpc_server extends IXR_Server {
'wp_author_display_name' => $author->display_name, 'wp_author_display_name' => $author->display_name,
'date_created_gmt' => new IXR_Date($post_date_gmt), 'date_created_gmt' => new IXR_Date($post_date_gmt),
'post_status' => $entry['post_status'], 'post_status' => $entry['post_status'],
'custom_fields' => $this->get_custom_fields($entry['ID']) 'custom_fields' => $this->get_custom_fields($entry['ID']),
'wp_post_format' => $post_format
); );
} }