Make WordPress Core


Ignore:
Timestamp:
03/23/2012 03:35:44 PM (13 years ago)
Author:
westi
Message:

XMLRPC: Add support for Feature Images to the new wp.xxxPost apis. See #18429 props maxcutler and markoheijen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r20215 r20270  
    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' )
     
    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
     
    776781
    777782            stick_post( $post_ID );
     783        }
     784
     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'] );
    778795        }
    779796
     
    33303347     *  - date_created_gmt
    33313348     *  - dateCreated
     3349     *  - wp_featured_image
    33323350     *
    33333351     * @since 1.5.0
     
    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;
     
    38753900        if ( isset($content_struct['custom_fields']) )
    38763901            $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
     3902
     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        }
    38773914
    38783915        // Handle enclosures
     
    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 {
     
    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
Note: See TracChangeset for help on using the changeset viewer.