Make WordPress Core


Ignore:
Timestamp:
12/05/2006 10:37:19 PM (18 years ago)
Author:
ryan
Message:

Attachment data abstraction from mdawaffe. fixes #3440

File:
1 edited

Legend:

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

    r4606 r4612  
    55//
    66
    7 function get_attached_file($attachment_id) {
    8     return get_post_meta($attachment_id, '_wp_attached_file', true);
     7function get_attached_file( $attachment_id, $unfiltered = false ) {
     8    $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
     9    if ( $unfiltered )
     10        return $file;
     11    return apply_filters( 'get_attached_file', $file, $attachment_id );
     12}
     13
     14function update_attached_file( $attachment_id, $file ) {
     15    if ( !get_post( $attachment_id ) )
     16        return false;
     17
     18    $old_file = get_attached_file( $attachment_id, true );
     19
     20    $file = apply_filters( 'update_attached_file', $file, $attachment_id );
     21
     22    if ( $old_file )
     23        return update_post_meta( $attachment_id, '_wp_attached_file', $file, $old_file );
     24    else
     25        return add_post_meta( $attachment_id, '_wp_attached_file', $file );
    926}
    1027
     
    13321349
    13331350    if ( $file )
    1334         add_post_meta($post_ID, '_wp_attached_file', $file);
     1351        update_attached_file( $post_ID, $file );
    13351352
    13361353    clean_post_cache($post_ID);
     
    13551372        return false;
    13561373
    1357     $meta = get_post_meta($postid, '_wp_attachment_metadata', true);
    1358     $file = get_post_meta($postid, '_wp_attached_file', true);
     1374    $meta = wp_get_attachment_metadata( $postid );
     1375    $file = get_attached_file( $postid );
    13591376
    13601377    $wpdb->query("DELETE FROM $wpdb->posts WHERE ID = '$postid'");
     
    13851402}
    13861403
     1404function wp_get_attachment_metadata( $post_id, $unfiltered = false ) {
     1405    $post_id = (int) $post_id;
     1406
     1407    $data = get_post_meta( $post_id, '_wp_attachment_metadata', true );
     1408    if ( $unfiltered )
     1409        return $data;
     1410    return apply_filters( 'wp_get_attachment_metadata', $data, $post_id );
     1411}
     1412
     1413function wp_update_attachment_metadata( $post_id, $data ) {
     1414    if ( !get_post( $post_id ) )
     1415        return false;
     1416
     1417    $old_data = wp_get_attachment_metadata( $post_id, true );
     1418
     1419    $data = apply_filters( 'wp_update_attachment_metadata', $data, $post_id );
     1420
     1421    if ( $old_data )
     1422        return update_post_meta( $post_id, '_wp_attachment_metadata', $data, $old_data );
     1423    else
     1424        return add_post_meta( $post_id, '_wp_attachment_metadata', $data );
     1425}
     1426
    13871427?>
Note: See TracChangeset for help on using the changeset viewer.