Mark import attachments as private. Schedule job to delete old import attachments. Introduce attachment context.
git-svn-id: http://svn.automattic.com/wordpress/branches/3.1@18023 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d8912e1b29
commit
1ff3c1e1a4
|
@ -337,7 +337,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
|
||||
|
|
|
@ -595,7 +595,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);
|
||||
|
@ -687,7 +688,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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -255,6 +255,7 @@ add_action( 'transition_post_status', '_transition_post_status', 5, 3 );
|
|||
add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' );
|
||||
add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
|
||||
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' );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -3532,10 +3538,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) )
|
||||
|
@ -3550,7 +3556,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) ) {
|
||||
|
@ -3653,6 +3661,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 {
|
||||
|
|
Loading…
Reference in New Issue