diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index 5bd996b752..28eec84e8e 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -338,7 +338,8 @@ if ( get_background_image() ) { 'post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, - 'guid' => $url + 'guid' => $url, + 'context' => 'custom-background' ); // Save the data diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index e58346e116..18fe4857f4 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -644,7 +644,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 'post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, - 'guid' => $url); + 'guid' => $url, + 'context' => 'custom-header'); // Save the data $id = wp_insert_attachment($object, $file); @@ -737,7 +738,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 'post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => 'image/jpeg', - 'guid' => $url + 'guid' => $url, + 'context' => 'custom-header' ); // Update the attachment diff --git a/wp-admin/includes/import.php b/wp-admin/includes/import.php index 51861bdcdb..f57be766c0 100644 --- a/wp-admin/includes/import.php +++ b/wp-admin/includes/import.php @@ -80,12 +80,17 @@ function wp_import_handle_upload() { $object = array( 'post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, - 'guid' => $url + 'guid' => $url, + 'context' => 'import', + 'post_status' => 'private' ); // Save the data $id = wp_insert_attachment( $object, $file ); + // schedule a cleanup for one day from now in case of failed import or missing wp_import_cleanup() call + wp_schedule_single_event( time() + 86400, 'importer_scheduled_cleanup', array( $id ) ); + return array( 'file' => $file, 'id' => $id ); } diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index a5a56ef7cb..237e3818c1 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -996,7 +996,12 @@ function wp_edit_attachments_query( $q = false ) { $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; $q['post_type'] = 'attachment'; - $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : 'inherit'; + $post_type = get_post_type_object( 'attachment' ); + $states = array( 'inherit' ); + if ( current_user_can( $post_type->cap->read_private_posts ) ) + $states[] = 'private'; + + $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states; $media_per_page = (int) get_user_option( 'upload_per_page' ); if ( empty( $media_per_page ) || $media_per_page < 1 ) $media_per_page = 20; diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 7584a491b5..a5b6150a51 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -257,6 +257,7 @@ add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); add_action( 'before_wp_tiny_mce', 'wp_print_editor_js' ); add_action( 'after_wp_tiny_mce', 'wp_preload_dialogs', 10, 1 ); add_action( 'admin_init', 'send_frame_options_header', 10, 0 ); +add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment' ); // Navigation menu actions add_action( 'delete_post', '_wp_delete_post_menu_item' ); diff --git a/wp-includes/post.php b/wp-includes/post.php index a930eda633..efec91be81 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -557,12 +557,18 @@ function get_post_status($ID = '') { if ( !is_object($post) ) return false; - // Unattached attachments are assumed to be published. - if ( ('attachment' == $post->post_type) && ('inherit' == $post->post_status) && ( 0 == $post->post_parent) ) - return 'publish'; + if ( 'attachment' == $post->post_type ) { + if ( 'private' == $post->post_status ) + return 'private'; - if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) ) - return get_post_status($post->post_parent); + // Unattached attachments are assumed to be published + if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) + return 'publish'; + + // Inherit status from the parent + if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) + return get_post_status($post->post_parent); + } return $post->post_status; } @@ -3543,10 +3549,10 @@ function is_local_attachment($url) { function wp_insert_attachment($object, $file = false, $parent = 0) { global $wpdb, $user_ID; - $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, + $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID, 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', - 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0); + 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => ''); $object = wp_parse_args($object, $defaults); if ( !empty($parent) ) @@ -3561,7 +3567,9 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { $post_author = $user_ID; $post_type = 'attachment'; - $post_status = 'inherit'; + + if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) ) + $post_status = 'inherit'; // Make sure we set a valid category. if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) { @@ -3664,6 +3672,9 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { if ( isset($post_parent) && $post_parent < 0 ) add_post_meta($post_ID, '_wp_attachment_temp_parent', $post_parent, true); + if ( ! empty( $context ) ) + add_post_meta( $post_ID, '_wp_attachment_context', $context, true ); + if ( $update) { do_action('edit_attachment', $post_ID); } else {