diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-12-07 10:17:25 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-12-07 10:17:25 +0000 |
commit | e7b243973132b555e66a0517e25232ba213bc35e (patch) | |
tree | ff9d04034493cc544d1064e56a1c8b8265d63b3f /wp-includes/post.php | |
parent | f57c5009b529dcc2494fc719f605ef64b7f9b4c7 (diff) | |
download | wordpress-mu-e7b243973132b555e66a0517e25232ba213bc35e.tar.gz wordpress-mu-e7b243973132b555e66a0517e25232ba213bc35e.tar.xz wordpress-mu-e7b243973132b555e66a0517e25232ba213bc35e.zip |
WP Merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@819 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/post.php')
-rw-r--r-- | wp-includes/post.php | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/wp-includes/post.php b/wp-includes/post.php index 5202c4c..0e9110e 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) { @@ -410,6 +427,8 @@ function wp_delete_post($postid = 0) { if ( 'page' == $post->post_type ) $wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_type = 'page'"); + $wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_type = 'attachment'"); + $wpdb->query("DELETE FROM $wpdb->posts WHERE ID = $postid"); $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID = $postid"); @@ -429,22 +448,12 @@ function wp_delete_post($postid = 0) { return $post; } -function wp_get_post_categories($post_ID = 0) { - global $wpdb; - - $post_ID = (int) $post_ID; - - $sql = "SELECT category_id - FROM $wpdb->post2cat - WHERE post_id = '$post_ID' - ORDER BY category_id"; - - $result = $wpdb->get_col($sql); - - if ( !$result ) - $result = array(); - - return array_unique($result); +function wp_get_post_categories($post_id = 0) { + $cats = &get_the_category($post_id); + $cat_ids = array(); + foreach ( $cats as $cat ) + $cat_ids[] = (int) $cat->cat_ID; + return array_unique($cat_ids); } function wp_get_recent_posts($num = 10) { @@ -1346,7 +1355,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); @@ -1369,8 +1378,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'"); @@ -1399,4 +1408,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 ); +} + ?> |