Make WordPress Core

Ticket #18429: dates_and_featured_image2.patch

File dates_and_featured_image2.patch, 4.6 KB (added by markoheijnen, 13 years ago)
  • wp-includes/class-wp-xmlrpc-server.php

     
    467467        }
    468468
    469469        /**
     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        /**
    470485         * Prepares post data for return in an XML-RPC object.
    471486         *
    472487         * @access private
     
    477492         */
    478493        function _prepare_post( $post, $fields ) {
    479494                // 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'] ) );
    481496
    482497                // prepare common post fields
    483498                $post_fields = array(
    484499                        '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'] ),
    489504                        'post_status'       => $post['post_status'],
    490505                        'post_type'         => $post['post_type'],
    491506                        'post_name'         => $post['post_name'],
     
    497512                        'comment_status'    => $post['comment_status'],
    498513                        'ping_status'       => $post['ping_status'],
    499514                        'sticky'            => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ),
     515                        'featured_image'    => get_post_meta( $post['ID'], '_thumbnail_id', true ),
    500516                );
    501517
    502518                // Consider future posts as published
     
    591607         *      - comment_status - can be 'open' | 'closed'
    592608         *      - ping_status - can be 'open' | 'closed'
    593609         *      - sticky
     610         *      - featured_image - ID of a media item to use as the featured image
    594611         *      - custom_fields - array, with each element containing 'key' and 'value'
    595612         *      - terms - array, with taxonomy names as keys and arrays of term IDs as values
    596613         *      - terms_names - array, with taxonomy names as keys and arrays of term names as values
     
    724741                        stick_post( $post_ID );
    725742                }
    726743
     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_thumbnail( $post_ID );
     748                        }
     749                        else {
     750                                $image = get_post( intval( $post_data['featured_image'] ), ARRAY_A );
     751
     752                                if ( empty( $image['ID'] ) )
     753                                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     754
     755                                if ( set_post_thumbnail( $post_ID, $image['ID'] ) === false )
     756                                        return new IXR_Error( 500, __( "Featured image couldn't be set" ) );
     757                        }
     758                        unset( $content_struct['featured_image'] );
     759                }
     760
    727761                if ( isset ( $post_data['custom_fields'] ) && post_type_supports( $post_data['post_type'], 'custom-fields' ) ) {
    728762                        $this->set_custom_fields( $post_ID, $post_data['custom_fields'] );
    729763                }
     
    880914                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    881915
    882916                // convert the date field back to IXR form
    883                 $post['post_date'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ) );
     917                $post['post_date'] = $this->_convert_date( $post['post_date'] );
    884918
    885919                // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
    886920                // since _insert_post will ignore the non-GMT date if the GMT date is set
    887921                if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) )
    888922                        unset( $post['post_date_gmt'] );
    889923                else
    890                         $post['post_date_gmt'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false ) );
     924                        $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
    891925
    892926                $this->escape( $post );
    893927                $merged_content_struct = array_merge( $post, $content_struct );
     
    10801114                                $query['order'] = $filter['order'];
    10811115                }
    10821116
    1083                 do_action( 'xmlrpc_call', 'wp.getPosts' );
    1084 
    10851117                $posts_list = wp_get_recent_posts( $query );
    10861118
    10871119                if ( ! $posts_list )