WordPress.org

Make WordPress Core

Changeset 16388


Ignore:
Timestamp:
11/15/2010 05:59:25 PM (8 years ago)
Author:
nacin
Message:

set_post_thumbnail(). fixes #15192.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r16371 r16388  
    14211421    }
    14221422
    1423     if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
    1424         $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
    1425         if ( !empty( $thumbnail_html ) ) {
    1426             update_post_meta( $post_ID, '_thumbnail_id', $thumbnail_id );
    1427             die( _wp_post_thumbnail_html( $thumbnail_id ) );
    1428         }
    1429     }
     1423    if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
     1424        die( _wp_post_thumbnail_html( $thumbnail_id ) );
    14301425    die( '0' );
    14311426    break;
  • trunk/wp-includes/post.php

    r16387 r16388  
    52585258}
    52595259
     5260/**
     5261 * Sets a post thumbnail.
     5262 *
     5263 * @since 3.1.0
     5264 *
     5265 * @param int|object $post Post ID or object where thumbnail should be attached.
     5266 * @param int $thumbnail_id Thumbnail to attach.
     5267 * @return bool True on success, false on failure.
     5268 */
     5269function set_post_thumbnail( $post, $thumbnail_id ) {
     5270    $post = get_post( $post );
     5271    if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
     5272        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
     5273        if ( ! empty( $thumbnail_html ) ) {
     5274            update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );
     5275            return true;
     5276        }
     5277    }
     5278    return false;
     5279}
     5280
    52605281?>
Note: See TracChangeset for help on using the changeset viewer.