3 * WordPress Administration Importer API.
6 * @subpackage Administration
10 * Retrieve list of importers.
16 function get_importers() {
18 if ( is_array($wp_importers) )
19 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
24 * Register importer for WordPress.
28 * @param string $id Importer tag. Used to uniquely identify importer.
29 * @param string $name Importer name and title.
30 * @param string $description Importer description.
31 * @param callback $callback Callback to run.
32 * @return WP_Error Returns WP_Error when $callback is WP_Error.
34 function register_importer( $id, $name, $description, $callback ) {
36 if ( is_wp_error( $callback ) )
38 $wp_importers[$id] = array ( $name, $description, $callback );
44 * Removes attachment based on ID.
48 * @param string $id Importer ID.
50 function wp_import_cleanup( $id ) {
51 wp_delete_attachment( $id );
55 * Handle importer uploading and add attachment.
61 function wp_import_handle_upload() {
62 $overrides = array( 'test_form' => false, 'test_type' => false );
63 $_FILES['import']['name'] .= '.txt';
64 $file = wp_handle_upload( $_FILES['import'], $overrides );
66 if ( isset( $file['error'] ) )
70 $type = $file['type'];
71 $file = addslashes( $file['file'] );
72 $filename = basename( $file );
74 // Construct the object array
75 $object = array( 'post_title' => $filename,
76 'post_content' => $url,
77 'post_mime_type' => $type,
82 $id = wp_insert_attachment( $object, $file );
84 return array( 'file' => $file, 'id' => $id );