101 |
101 |
102 if ( isset( $upload['error'] ) ) { |
102 if ( isset( $upload['error'] ) ) { |
103 return $upload; |
103 return $upload; |
104 } |
104 } |
105 |
105 |
106 // Construct the object array. |
106 // Construct the attachment array. |
107 $object = array( |
107 $attachment = array( |
108 'post_title' => wp_basename( $upload['file'] ), |
108 'post_title' => wp_basename( $upload['file'] ), |
109 'post_content' => $upload['url'], |
109 'post_content' => $upload['url'], |
110 'post_mime_type' => $upload['type'], |
110 'post_mime_type' => $upload['type'], |
111 'guid' => $upload['url'], |
111 'guid' => $upload['url'], |
112 'context' => 'import', |
112 'context' => 'import', |
113 'post_status' => 'private', |
113 'post_status' => 'private', |
114 ); |
114 ); |
115 |
115 |
116 // Save the data. |
116 // Save the data. |
117 $id = wp_insert_attachment( $object, $upload['file'] ); |
117 $id = wp_insert_attachment( $attachment, $upload['file'] ); |
118 |
118 |
119 /* |
119 /* |
120 * Schedule a cleanup for one day from now in case of failed |
120 * Schedule a cleanup for one day from now in case of failed |
121 * import or missing wp_import_cleanup() call. |
121 * import or missing wp_import_cleanup() call. |
122 */ |
122 */ |