Make WordPress Core

Changeset 4612


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

Attachment data abstraction from mdawaffe. fixes #3440

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r4610 r4612  
    20172017
    20182018    $icon = get_attachment_icon( $post->ID );
    2019     $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
     2019    $attachment_data = wp_get_attachment_metadata( $id );
    20202020    $thumb = isset( $attachment_data['thumb'] );
    20212021?>
  • trunk/wp-admin/page.php

    r4424 r4612  
    7272
    7373    // Update the thumbnail filename
    74     $oldmeta = $newmeta = get_post_meta($page_id, '_wp_attachment_metadata', true);
     74    $newmeta = wp_get_attachment_metadata( $page_id, true );
    7575    $newmeta['thumb'] = $_POST['thumb'];
    7676
    77     if ( '' !== $oldmeta )
    78         update_post_meta($page_id, '_wp_attachment_metadata', $newmeta, $oldmeta);
    79     else
    80         add_post_meta($page_id, '_wp_attachment_metadata', $newmeta);
     77    wp_update_attachment_metadata( $newmeta );
    8178
    8279case 'editpost':
  • trunk/wp-admin/post.php

    r4495 r4612  
    7979
    8080    // Update the thumbnail filename
    81     $oldmeta = $newmeta = get_post_meta($post_id, '_wp_attachment_metadata', true);
     81    $newmeta = wp_get_attachment_metadata( $post_id, true );
    8282    $newmeta['thumb'] = $_POST['thumb'];
    8383
    84     if ( '' !== $oldmeta )
    85         update_post_meta($post_id, '_wp_attachment_metadata', $newmeta, $oldmeta);
    86     else
    87         add_post_meta($post_id, '_wp_attachment_metadata', $newmeta);
     84    wp_update_attachment_metadata( $post_id, $newmeta );
    8885
    8986case 'editpost':
  • trunk/wp-admin/upgrade-functions.php

    r4556 r4612  
    467467            $meta = get_post_meta($object->ID, 'imagedata', true);
    468468            if ( ! empty($meta['file']) )
    469                 add_post_meta($object->ID, '_wp_attached_file', $meta['file']);
     469                update_attached_file( $object->ID, $meta['file'] );
    470470        }
    471471    }
  • trunk/wp-admin/upload-functions.php

    r4466 r4612  
    33    global $post;
    44    $id = get_the_ID();
    5     $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
     5    $attachment_data = wp_get_attachment_metadata( $id );
    66    if ( isset($attachment_data['width']) )
    77        list($width,$height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128);
     
    5858    global $style, $post_id, $style;
    5959    $id = get_the_ID();
    60     $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
     60    $attachment_data = wp_get_attachment_metadata( $id );
    6161?>
    6262    <div id="upload-file">
     
    9999    if ( $id ) :
    100100        $attachment = get_post_to_edit( $id );
    101         $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
     101        $attachment_data = wp_get_attachment_metadata( $id );
    102102?>
    103103        <div id="file-title">
     
    230230            $imagedata['file'] = $file;
    231231
    232             add_post_meta($id, '_wp_attachment_metadata', $imagedata);
     232            wp_update_attachment_metadata( $id, $imagedata );
    233233
    234234            if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
     
    241241                    $newdata = $imagedata;
    242242                    $newdata['thumb'] = basename($thumb);
    243                     update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
     243                    wp_update_attachment_metadata( $id, $newdata );
    244244                } else {
    245245                    $error = $thumb;
     
    247247            }
    248248        } else {
    249             add_post_meta($id, '_wp_attachment_metadata', array());
     249            wp_update_attachment_metadata( $id, array() );
    250250        }
    251251
  • trunk/wp-includes/post-template.php

    r4603 r4612  
    354354    $mime = $post->post_mime_type;
    355355
    356     $imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true);
    357 
    358     $file = get_post_meta($post->ID, '_wp_attached_file', true);
     356    $imagedata = wp_get_attachment_metadata( $post->ID );
     357
     358    $file = get_attached_file( $post->ID );
    359359
    360360    $exts = array('jpg', 'gif', 'png');
    361 
    362361    if ( !$fullsize && !empty($imagedata['thumb'])
    363362            && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
  • 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?>
  • trunk/xmlrpc.php

    r4569 r4612  
    872872        );
    873873        // Save the data
    874         $id = wp_insert_attachment($attachment, $upload[ 'file' ], $post_id);
    875         add_post_meta($id, '_wp_attachment_metadata', array());
     874        $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
     875        wp_update_attachment_metadata( $id, array() );
    876876
    877877        return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
Note: See TracChangeset for help on using the changeset viewer.