Changeset 3303 for trunk/wp-includes/functions-post.php
- Timestamp:
- 12/13/2005 07:19:56 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions-post.php
r3291 r3303 209 209 } 210 210 211 function wp_insert_attachment($object, $file , $post_parent = 0) {211 function wp_insert_attachment($object, $file = false, $post_parent = 0) { 212 212 global $wpdb, $user_ID; 213 213 214 214 if ( is_object($object) ) 215 215 $object = get_object_vars($object); 216 216 217 217 // Export array as variables 218 218 extract($object); … … 321 321 wp_set_post_cats('', $post_ID, $post_category); 322 322 323 add_post_meta($post_ID, '_wp_attached_file', $file); 323 if ( $file ) 324 add_post_meta($post_ID, '_wp_attached_file', $file); 324 325 325 326 clean_post_cache($post_ID); … … 344 345 return false; 345 346 346 $meta = get_post_meta($postid, ' imagedata', true);347 $meta = get_post_meta($postid, '_wp_attachment_metadata', true); 347 348 $file = get_post_meta($postid, '_wp_attached_file', true); 348 349 … … 355 356 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid"); 356 357 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 } 359 363 360 364 if ( ! empty($file) ) … … 429 433 $postarr['post_date_gmt'] = ''; 430 434 } 435 436 if ($postarr['post_status'] == 'attachment') 437 return wp_insert_attachment($postarr); 431 438 432 439 return wp_insert_post($postarr); … … 511 518 if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") ) 512 519 return $post; 520 521 if ( 'attachment' == $post->post_status ) 522 return wp_delete_attachment($postid); 513 523 514 524 do_action('delete_post', $postid);
Note: See TracChangeset
for help on using the changeset viewer.