Ticket #18429: dates_and_featured_image.patch
File dates_and_featured_image.patch, 4.5 KB (added by , 13 years ago) |
---|
-
wp-includes/class-wp-xmlrpc-server.php
467 467 } 468 468 469 469 /** 470 * Convert a WordPress date string to an IXR_Date object. 471 * 472 * @access protected 473 * 474 * @param $date 475 * @return IXR_Date 476 */ 477 protected function _convert_date( $date ) { 478 if ( $date === '0000-00-00 00:00:00' ) { 479 return new IXR_Date( '00000000T00:00:00Z' ); 480 } 481 return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) ); 482 } 483 484 /** 470 485 * Prepares post data for return in an XML-RPC object. 471 486 * 472 487 * @access private … … 477 492 */ 478 493 function _prepare_post( $post, $fields ) { 479 494 // holds the data for this post. built up based on $fields 480 $_post = array( 'post_id' => $post['ID']);495 $_post = array( 'post_id' => strval( $post['ID'] ) ); 481 496 482 497 // prepare common post fields 483 498 $post_fields = array( 484 499 'post_title' => $post['post_title'], 485 'post_date' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false )),486 'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false )),487 'post_modified' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_modified'], false )),488 'post_modified_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_modified_gmt'], false )),500 'post_date' => $this->_convert_date( $post['post_date'] ), 501 'post_date_gmt' => $this->_convert_date( $post['post_date_gmt'] ), 502 'post_modified' => $this->_convert_date( $post['post_modified'] ), 503 'post_modified_gmt' => $this->_convert_date( $post['post_modified_gmt'] ), 489 504 'post_status' => $post['post_status'], 490 505 'post_type' => $post['post_type'], 491 506 'post_name' => $post['post_name'], … … 497 512 'comment_status' => $post['comment_status'], 498 513 'ping_status' => $post['ping_status'], 499 514 'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), 515 'featured_image' => get_post_meta( $post['ID'], '_thumbnail_id', true ), 500 516 ); 501 517 502 518 // Consider future posts as published … … 591 607 * - comment_status - can be 'open' | 'closed' 592 608 * - ping_status - can be 'open' | 'closed' 593 609 * - sticky 610 * - featured_image - ID of a media item to use as the featured image 594 611 * - custom_fields - array, with each element containing 'key' and 'value' 595 612 * - terms - array, with taxonomy names as keys and arrays of term IDs as values 596 613 * - terms_names - array, with taxonomy names as keys and arrays of term names as values … … 724 741 stick_post( $post_ID ); 725 742 } 726 743 744 if ( isset ( $post_data['featured_image'] ) ) { 745 // empty value deletes, non-empty value adds/updates 746 if ( empty( $post_data['featured_image'] ) ) { 747 delete_post_meta( $post_ID, '_thumbnail_id' ); 748 } 749 else { 750 $image = get_post( intval( $post_data['featured_image'] ), ARRAY_A ); 751 if ( empty($image['ID'] ) ) 752 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 753 update_post_meta( $post_ID, '_thumbnail_id', $image['ID'] ); 754 } 755 unset( $content_struct['featured_image'] ); 756 } 757 727 758 if ( isset ( $post_data['custom_fields'] ) && post_type_supports( $post_data['post_type'], 'custom-fields' ) ) { 728 759 $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); 729 760 } … … 880 911 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); 881 912 882 913 // convert the date field back to IXR form 883 $post['post_date'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ));914 $post['post_date'] = $this->_convert_date( $post['post_date'] ); 884 915 885 916 // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, 886 917 // since _insert_post will ignore the non-GMT date if the GMT date is set 887 918 if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) 888 919 unset( $post['post_date_gmt'] ); 889 920 else 890 $post['post_date_gmt'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false ));921 $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); 891 922 892 923 $this->escape( $post ); 893 924 $merged_content_struct = array_merge( $post, $content_struct ); … … 1080 1111 $query['order'] = $filter['order']; 1081 1112 } 1082 1113 1083 do_action( 'xmlrpc_call', 'wp.getPosts' );1084 1085 1114 $posts_list = wp_get_recent_posts( $query ); 1086 1115 1087 1116 if ( ! $posts_list )