web/wp-admin/includes/import.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    54 /**
    54 /**
    55  * Handle importer uploading and add attachment.
    55  * Handle importer uploading and add attachment.
    56  *
    56  *
    57  * @since 2.0.0
    57  * @since 2.0.0
    58  *
    58  *
    59  * @return array
    59  * @return array Uploaded file's details on success, error message on failure
    60  */
    60  */
    61 function wp_import_handle_upload() {
    61 function wp_import_handle_upload() {
    62 	if ( !isset($_FILES['import']) ) {
    62 	if ( !isset($_FILES['import']) ) {
    63 		$file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' );
    63 		$file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' );
    64 		return $file;
    64 		return $file;
    71 	if ( isset( $file['error'] ) )
    71 	if ( isset( $file['error'] ) )
    72 		return $file;
    72 		return $file;
    73 
    73 
    74 	$url = $file['url'];
    74 	$url = $file['url'];
    75 	$type = $file['type'];
    75 	$type = $file['type'];
    76 	$file = addslashes( $file['file'] );
    76 	$file = $file['file'];
    77 	$filename = basename( $file );
    77 	$filename = basename( $file );
    78 
    78 
    79 	// Construct the object array
    79 	// Construct the object array
    80 	$object = array( 'post_title' => $filename,
    80 	$object = array( 'post_title' => $filename,
    81 		'post_content' => $url,
    81 		'post_content' => $url,
    82 		'post_mime_type' => $type,
    82 		'post_mime_type' => $type,
    83 		'guid' => $url
    83 		'guid' => $url,
       
    84 		'context' => 'import',
       
    85 		'post_status' => 'private'
    84 	);
    86 	);
    85 
    87 
    86 	// Save the data
    88 	// Save the data
    87 	$id = wp_insert_attachment( $object, $file );
    89 	$id = wp_insert_attachment( $object, $file );
    88 
    90 
       
    91 	// schedule a cleanup for one day from now in case of failed import or missing wp_import_cleanup() call
       
    92 	wp_schedule_single_event( time() + 86400, 'importer_scheduled_cleanup', array( $id ) );
       
    93 
    89 	return array( 'file' => $file, 'id' => $id );
    94 	return array( 'file' => $file, 'id' => $id );
    90 }
    95 }
    91 
       
    92 ?>