Make WordPress Core


Ignore:
Timestamp:
12/13/2005 07:19:56 PM (20 years ago)
Author:
ryan
Message:

Attachment enhancements from skeltoac. fixes #2074

File:
1 edited

Legend:

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

    r3291 r3303  
    209209}
    210210
    211 function wp_insert_attachment($object, $file, $post_parent = 0) {
     211function wp_insert_attachment($object, $file = false, $post_parent = 0) {
    212212    global $wpdb, $user_ID;
    213213
    214214    if ( is_object($object) )
    215215        $object = get_object_vars($object);
    216    
     216
    217217    // Export array as variables
    218218    extract($object);
     
    321321    wp_set_post_cats('', $post_ID, $post_category);
    322322
    323     add_post_meta($post_ID, '_wp_attached_file', $file);
     323    if ( $file )
     324        add_post_meta($post_ID, '_wp_attached_file', $file);
    324325
    325326    clean_post_cache($post_ID);
     
    344345        return false;
    345346
    346     $meta = get_post_meta($postid, 'imagedata', true);
     347    $meta = get_post_meta($postid, '_wp_attachment_metadata', true);
    347348    $file = get_post_meta($postid, '_wp_attached_file', true);
    348349
     
    355356    $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
    356357
    357     if ( ! empty($meta['file']) )
    358         @ unlink($meta['file']);
     358    if ( ! empty($meta['thumb']) ) {
     359        // Don't delete the thumb if another attachment uses it
     360        if (! $foo = $wpdb->get_row("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%".$wpdb->escape($meta['thumb'])."%' AND post_id <> $postid"))
     361            @ unlink(str_replace(basename($file), $meta['thumb'], $file));
     362    }
    359363
    360364    if ( ! empty($file) )
     
    429433        $postarr['post_date_gmt'] = '';
    430434    }
     435
     436    if ($postarr['post_status'] == 'attachment')
     437        return wp_insert_attachment($postarr);
    431438
    432439    return wp_insert_post($postarr);
     
    511518    if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
    512519        return $post;
     520
     521    if ( 'attachment' == $post->post_status )
     522        return wp_delete_attachment($postid);
    513523
    514524    do_action('delete_post', $postid);
Note: See TracChangeset for help on using the changeset viewer.