Mark import attachments as private. Schedule job to delete old import attachments. Introduce attachment context.

git-svn-id: http://svn.automattic.com/wordpress/trunk@17999 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2011-05-22 23:25:28 +00:00
parent 23d781a06e
commit 2cfb1592f0
6 changed files with 38 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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 );
}

View File

@ -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;

View File

@ -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' );

View File

@ -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) )
if ( 'attachment' == $post->post_type ) {
if ( 'private' == $post->post_status )
return 'private';
// Unattached attachments are assumed to be published
if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) )
return 'publish';
if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) )
// 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,6 +3567,8 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
$post_author = $user_ID;
$post_type = 'attachment';
if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) )
$post_status = 'inherit';
// Make sure we set a valid 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 {