@@ -98,7 +98,7 @@ function wp_upload_form() {
128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
@@ -240,13 +240,13 @@ function wp_upload_tab_upload_action() {
if ( @file_exists($thumb) ) {
$newdata = $imagedata;
$newdata['thumb'] = basename($thumb);
- update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
+ wp_update_attachment_metadata( $id, $newdata );
} else {
$error = $thumb;
}
}
} else {
- add_post_meta($id, '_wp_attachment_metadata', array());
+ wp_update_attachment_metadata( $id, array() );
}
wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id");
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index a4a9c6f415..e1d83c5cd5 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -353,12 +353,11 @@ function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) {
$mime = $post->post_mime_type;
- $imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true);
+ $imagedata = wp_get_attachment_metadata( $post->ID );
- $file = get_post_meta($post->ID, '_wp_attached_file', true);
+ $file = get_attached_file( $post->ID );
$exts = array('jpg', 'gif', 'png');
-
if ( !$fullsize && !empty($imagedata['thumb'])
&& ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
&& file_exists($thumbfile) ) {
diff --git a/wp-includes/post.php b/wp-includes/post.php
index 661c38b3b5..ddfe815a5d 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -4,8 +4,25 @@
// Post functions
//
-function get_attached_file($attachment_id) {
- return get_post_meta($attachment_id, '_wp_attached_file', true);
+function get_attached_file( $attachment_id, $unfiltered = false ) {
+ $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
+ if ( $unfiltered )
+ return $file;
+ return apply_filters( 'get_attached_file', $file, $attachment_id );
+}
+
+function update_attached_file( $attachment_id, $file ) {
+ if ( !get_post( $attachment_id ) )
+ return false;
+
+ $old_file = get_attached_file( $attachment_id, true );
+
+ $file = apply_filters( 'update_attached_file', $file, $attachment_id );
+
+ if ( $old_file )
+ return update_post_meta( $attachment_id, '_wp_attached_file', $file, $old_file );
+ else
+ return add_post_meta( $attachment_id, '_wp_attached_file', $file );
}
function &get_children($args = '', $output = OBJECT) {
@@ -1331,7 +1348,7 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) {
wp_set_post_categories($post_ID, $post_category);
if ( $file )
- add_post_meta($post_ID, '_wp_attached_file', $file);
+ update_attached_file( $post_ID, $file );
clean_post_cache($post_ID);
@@ -1354,8 +1371,8 @@ function wp_delete_attachment($postid) {
if ( 'attachment' != $post->post_type )
return false;
- $meta = get_post_meta($postid, '_wp_attachment_metadata', true);
- $file = get_post_meta($postid, '_wp_attached_file', true);
+ $meta = wp_get_attachment_metadata( $postid );
+ $file = get_attached_file( $postid );
$wpdb->query("DELETE FROM $wpdb->posts WHERE ID = '$postid'");
@@ -1384,4 +1401,27 @@ function wp_delete_attachment($postid) {
return $post;
}
+function wp_get_attachment_metadata( $post_id, $unfiltered = false ) {
+ $post_id = (int) $post_id;
+
+ $data = get_post_meta( $post_id, '_wp_attachment_metadata', true );
+ if ( $unfiltered )
+ return $data;
+ return apply_filters( 'wp_get_attachment_metadata', $data, $post_id );
+}
+
+function wp_update_attachment_metadata( $post_id, $data ) {
+ if ( !get_post( $post_id ) )
+ return false;
+
+ $old_data = wp_get_attachment_metadata( $post_id, true );
+
+ $data = apply_filters( 'wp_update_attachment_metadata', $data, $post_id );
+
+ if ( $old_data )
+ return update_post_meta( $post_id, '_wp_attachment_metadata', $data, $old_data );
+ else
+ return add_post_meta( $post_id, '_wp_attachment_metadata', $data );
+}
+
?>
diff --git a/xmlrpc.php b/xmlrpc.php
index 60301b4614..61126ae1e9 100644
--- a/xmlrpc.php
+++ b/xmlrpc.php
@@ -871,8 +871,8 @@ class wp_xmlrpc_server extends IXR_Server {
'guid' => $upload[ 'url' ]
);
// Save the data
- $id = wp_insert_attachment($attachment, $upload[ 'file' ], $post_id);
- add_post_meta($id, '_wp_attachment_metadata', array());
+ $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
+ wp_update_attachment_metadata( $id, array() );
return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
}