Make WordPress Core

Ticket #3440: 3440.diff

File 3440.diff, 8.2 KB (added by mdawaffe, 18 years ago)
  • wp-includes/post-template.php

     
    353353
    354354        $mime = $post->post_mime_type;
    355355
    356         $imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true);
     356        $imagedata = wp_get_attachment_metadata( $post->ID );
    357357
    358         $file = get_post_meta($post->ID, '_wp_attached_file', true);
     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))
    364363                        && file_exists($thumbfile) ) {
  • wp-includes/post.php

     
    44// Post functions
    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 );
    912}
    1013
     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 );
     26}
     27
    1128function &get_children($args = '', $output = OBJECT) {
    1229        global $post_cache, $wpdb, $blog_id;
    1330
     
    13311348        wp_set_post_categories($post_ID, $post_category);
    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);
    13371354
     
    13541371        if ( 'attachment' != $post->post_type )
    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'");
    13611378
     
    13841401        return $post;
    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?>
  • xmlrpc.php

     
    871871                        'guid' => $upload[ 'url' ]
    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 ) );
    878878        }
  • wp-admin/post.php

     
    7878        $_POST['post_type'] = 'attachment';
    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':
    9087        $post_ID = (int) $_POST['post_ID'];
  • wp-admin/upgrade-functions.php

     
    466466
    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        }
    472472}
  • wp-admin/admin-functions.php

     
    20162016                return false;
    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?>
    20222022<form id="the-attachment-links">
  • wp-admin/upload-functions.php

     
    22function wp_upload_display( $dims = false, $href = '' ) {
    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);
    88        ob_start();
     
    5757function wp_upload_view() {
    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">
    6363                <div id="file-title">
     
    9898<?php
    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">
    104104                        <h2><?php if ( !isset($attachment_data['width']) && 'inline' != $style )
     
    229229                        $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
    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 ) {
    235235                                if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
     
    240240                                if ( @file_exists($thumb) ) {
    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;
    246246                                }
    247247                        }
    248248                } else {
    249                         add_post_meta($id, '_wp_attachment_metadata', array());
     249                        wp_update_attachment_metadata( $id, array() );
    250250                }
    251251
    252252                wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id");
  • wp-admin/page.php

     
    7171        $_POST['post_type'] = 'attachment';
    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':
    8380        $page_ID = (int) $_POST['post_ID'];