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
git-svn-id: http://core.svn.wordpress.org/trunk@21967 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0277a024e4
commit
bc3c170305
|
@ -207,9 +207,10 @@ function update_attached_file( $attachment_id, $file ) {
|
|||
return false;
|
||||
|
||||
$file = apply_filters( 'update_attached_file', $file, $attachment_id );
|
||||
$file = _wp_relative_upload_path($file);
|
||||
|
||||
return update_post_meta( $attachment_id, '_wp_attached_file', $file );
|
||||
if ( $file = _wp_relative_upload_path( $file ) )
|
||||
return update_post_meta( $attachment_id, '_wp_attached_file', $file );
|
||||
else
|
||||
return delete_post_meta( $attachment_id, '_wp_attached_file' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4028,9 +4029,10 @@ function wp_update_attachment_metadata( $post_id, $data ) {
|
|||
if ( !$post = get_post( $post_id ) )
|
||||
return false;
|
||||
|
||||
$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
|
||||
|
||||
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data);
|
||||
if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) )
|
||||
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
|
||||
else
|
||||
return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5208,10 +5210,10 @@ function set_post_thumbnail( $post, $thumbnail_id ) {
|
|||
$post = get_post( $post );
|
||||
$thumbnail_id = absint( $thumbnail_id );
|
||||
if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
|
||||
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
|
||||
if ( ! empty( $thumbnail_html ) ) {
|
||||
if ( $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) )
|
||||
return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );
|
||||
}
|
||||
else
|
||||
return delete_post_meta( $post->ID, '_thumbnail_id' );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue