diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php index 940f55653a..3952c2234c 100644 --- a/wp-includes/class-wp-xmlrpc-server.php +++ b/wp-includes/class-wp-xmlrpc-server.php @@ -577,6 +577,10 @@ class wp_xmlrpc_server extends IXR_Server { 'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), ); + // + $post_fields['featured_image'] = get_post_meta( $post['ID'], '_thumbnail_id', true ); + $post_fields['featured_image_url'] = wp_get_attachment_url( $post_fields['featured_image'] ); + // Consider future posts as published if ( $post_fields['post_status'] === 'future' ) $post_fields['post_status'] = 'publish'; @@ -644,6 +648,7 @@ class wp_xmlrpc_server extends IXR_Server { * - comment_status - can be 'open' | 'closed' * - ping_status - can be 'open' | 'closed' * - sticky + * - featured_image - ID of a media item to use as the featured image * - custom_fields - array, with each element containing 'key' and 'value' * - terms - array, with taxonomy names as keys and arrays of term IDs as values * - terms_names - array, with taxonomy names as keys and arrays of term names as values @@ -777,6 +782,18 @@ class wp_xmlrpc_server extends IXR_Server { stick_post( $post_ID ); } + if ( isset ( $post_data['featured_image'] ) ) { + // empty value deletes, non-empty value adds/updates + if ( empty( $post_data['featured_image'] ) ) { + delete_post_thumbnail( $post_ID ); + } + else { + if ( set_post_thumbnail( $post_ID, $post_data['featured_image'] ) === false ) + return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); + } + unset( $content_struct['featured_image'] ); + } + if ( isset ( $post_data['custom_fields'] ) && post_type_supports( $post_data['post_type'], 'custom-fields' ) ) { $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); } @@ -3329,6 +3346,7 @@ class wp_xmlrpc_server extends IXR_Server { * - mt_allow_pings - can be 'open' or 'closed' * - date_created_gmt * - dateCreated + * - wp_featured_image * * @since 1.5.0 * @@ -3575,6 +3593,13 @@ class wp_xmlrpc_server extends IXR_Server { if ( isset($content_struct['custom_fields']) ) $this->set_custom_fields($post_ID, $content_struct['custom_fields']); + if ( isset ( $post_data['wp_featured_image'] ) ) { + if ( set_post_thumbnail( $post_ID, $post_data['wp_featured_image'] ) === false ) + return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); + + unset( $content_struct['wp_featured_image'] ); + } + // Handle enclosures $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; $this->add_enclosure_if_new($post_ID, $thisEnclosure); @@ -3875,6 +3900,18 @@ class wp_xmlrpc_server extends IXR_Server { if ( isset($content_struct['custom_fields']) ) $this->set_custom_fields($post_ID, $content_struct['custom_fields']); + if ( isset ( $post_data['wp_featured_image'] ) ) { + // empty value deletes, non-empty value adds/updates + if ( empty( $post_data['wp_featured_image'] ) ) { + delete_post_thumbnail( $post_ID ); + } + else { + if ( set_post_thumbnail( $post_ID, $post_data['wp_featured_image'] ) === false ) + return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); + } + unset( $content_struct['wp_featured_image'] ); + } + // Handle enclosures $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; $this->add_enclosure_if_new($post_ID, $thisEnclosure); @@ -4011,6 +4048,9 @@ class wp_xmlrpc_server extends IXR_Server { if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure; + $resp['wp_featured_image'] = get_post_meta( $postdata['ID'], '_thumbnail_id', true ); + $resp['wp_featured_image_url'] = wp_get_attachment_url( $resp['wp_featured_image'] ); + return $resp; } else { return new IXR_Error(404, __('Sorry, no such post.')); @@ -4125,6 +4165,9 @@ class wp_xmlrpc_server extends IXR_Server { 'date_modified_gmt' => new IXR_Date( $post_modified_gmt ) ); + $entry_index = count( $struct ) - 1; + $struct[ $entry_index ][ 'wp_featured_image' ] = get_post_meta( $entry['ID'], '_thumbnail_id', true ); + $struct[ $entry_index ][ 'wp_featured_image_url' ] = wp_get_attachment_url( $struct[ $entry_index ][ 'wp_featured_image' ] ); } $recent_posts = array();