WordPress.org

Make WordPress Core

Changeset 21967


Ignore:
Timestamp:
09/24/12 13:07:34 (3 years ago)
Author:
ryan
Message:

Don't add empty _wp_attached_file, _wp_attachment_metadata, _thumbnail_id meta to posts. Delete these fields when set to empty. Props SergeyBiryukov, Caspie. fixes #16391

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r21953 r21967  
    208208 
    209209    $file = apply_filters( 'update_attached_file', $file, $attachment_id ); 
    210     $file = _wp_relative_upload_path($file); 
    211  
    212     return update_post_meta( $attachment_id, '_wp_attached_file', $file ); 
     210    if ( $file = _wp_relative_upload_path( $file ) ) 
     211        return update_post_meta( $attachment_id, '_wp_attached_file', $file ); 
     212    else 
     213        return delete_post_meta( $attachment_id, '_wp_attached_file' ); 
    213214} 
    214215 
     
    40294030        return false; 
    40304031 
    4031     $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ); 
    4032  
    4033     return update_post_meta( $post->ID, '_wp_attachment_metadata', $data); 
     4032    if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) 
     4033        return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 
     4034    else 
     4035        return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); 
    40344036} 
    40354037 
     
    52095211    $thumbnail_id = absint( $thumbnail_id ); 
    52105212    if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { 
    5211         $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); 
    5212         if ( ! empty( $thumbnail_html ) ) { 
     5213        if ( $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) 
    52135214            return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); 
    5214         } 
     5215        else 
     5216            return delete_post_meta( $post->ID, '_thumbnail_id' ); 
    52155217    } 
    52165218    return false; 
Note: See TracChangeset for help on using the changeset viewer.