WordPress.org

Make WordPress Core

Ticket #18429: featured_image.patch

File featured_image.patch, 4.0 KB (added by markoheijnen, 6 years ago)
  • wp-includes/class-wp-xmlrpc-server.php

     
    577577                        'sticky'            => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ),
    578578                );
    579579
     580                //
     581                $post_fields['featured_image']     = get_post_meta( $post['ID'], '_thumbnail_id', true );
     582                $post_fields['featured_image_url'] = wp_get_attachment_url( $post_fields['featured_image'] );
     583
    580584                // Consider future posts as published
    581585                if ( $post_fields['post_status'] === 'future' )
    582586                        $post_fields['post_status'] = 'publish';
     
    644648         *      - comment_status - can be 'open' | 'closed'
    645649         *      - ping_status - can be 'open' | 'closed'
    646650         *      - sticky
     651         *      - featured_image - ID of a media item to use as the featured image
    647652         *      - custom_fields - array, with each element containing 'key' and 'value'
    648653         *      - terms - array, with taxonomy names as keys and arrays of term IDs as values
    649654         *      - terms_names - array, with taxonomy names as keys and arrays of term names as values
     
    777782                        stick_post( $post_ID );
    778783                }
    779784
     785                if ( isset ( $post_data['featured_image'] ) ) {
     786                        // empty value deletes, non-empty value adds/updates
     787                        if ( empty( $post_data['featured_image'] ) ) {
     788                                delete_post_thumbnail( $post_ID );
     789                        }
     790                        else {
     791                                if ( set_post_thumbnail( $post_ID, $post_data['featured_image'] ) === false )
     792                                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     793                        }
     794                        unset( $content_struct['featured_image'] );
     795                }
     796
    780797                if ( isset ( $post_data['custom_fields'] ) && post_type_supports( $post_data['post_type'], 'custom-fields' ) ) {
    781798                        $this->set_custom_fields( $post_ID, $post_data['custom_fields'] );
    782799                }
     
    33293346         *  - mt_allow_pings - can be 'open' or 'closed'
    33303347         *  - date_created_gmt
    33313348         *  - dateCreated
     3349         *  - wp_featured_image
    33323350         *
    33333351         * @since 1.5.0
    33343352         *
     
    35753593                if ( isset($content_struct['custom_fields']) )
    35763594                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    35773595
     3596                if ( isset ( $post_data['wp_featured_image'] ) ) {
     3597                        if ( set_post_thumbnail( $post_ID, $post_data['wp_featured_image'] ) === false )
     3598                                return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     3599
     3600                        unset( $content_struct['wp_featured_image'] );
     3601                }
     3602
    35783603                // Handle enclosures
    35793604                $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
    35803605                $this->add_enclosure_if_new($post_ID, $thisEnclosure);
     
    38753900                if ( isset($content_struct['custom_fields']) )
    38763901                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    38773902
     3903                if ( isset ( $post_data['wp_featured_image'] ) ) {
     3904                        // empty value deletes, non-empty value adds/updates
     3905                        if ( empty( $post_data['wp_featured_image'] ) ) {
     3906                                delete_post_thumbnail( $post_ID );
     3907                        }
     3908                        else {
     3909                                if ( set_post_thumbnail( $post_ID, $post_data['wp_featured_image'] ) === false )
     3910                                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     3911                        }
     3912                        unset( $content_struct['wp_featured_image'] );
     3913                }
     3914
    38783915                // Handle enclosures
    38793916                $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
    38803917                $this->add_enclosure_if_new($post_ID, $thisEnclosure);
     
    40114048
    40124049                        if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure;
    40134050
     4051                        $resp['wp_featured_image'] = get_post_meta( $postdata['ID'], '_thumbnail_id', true );
     4052                        $resp['wp_featured_image_url'] = wp_get_attachment_url( $resp['wp_featured_image'] );
     4053
    40144054                        return $resp;
    40154055                } else {
    40164056                        return new IXR_Error(404, __('Sorry, no such post.'));
     
    41254165                                'date_modified_gmt' => new IXR_Date( $post_modified_gmt )
    41264166                        );
    41274167
     4168                        $entry_index = count( $struct ) - 1;
     4169                        $struct[ $entry_index ][ 'wp_featured_image' ]     = get_post_meta( $entry['ID'], '_thumbnail_id', true );
     4170                        $struct[ $entry_index ][ 'wp_featured_image_url' ] = wp_get_attachment_url( $struct[ $entry_index ][ 'wp_featured_image' ] );
    41284171                }
    41294172
    41304173                $recent_posts = array();