mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Administration Importer API.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Retrieve list of importers.
mp-wp_genesis 11 *
mp-wp_genesis 12 * @since 2.0.0
mp-wp_genesis 13 *
mp-wp_genesis 14 * @return array
mp-wp_genesis 15 */
mp-wp_genesis 16 function get_importers() {
mp-wp_genesis 17 global $wp_importers;
mp-wp_genesis 18 if ( is_array($wp_importers) )
mp-wp_genesis 19 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
mp-wp_genesis 20 return $wp_importers;
mp-wp_genesis 21 }
mp-wp_genesis 22
mp-wp_genesis 23 /**
mp-wp_genesis 24 * Register importer for WordPress.
mp-wp_genesis 25 *
mp-wp_genesis 26 * @since 2.0.0
mp-wp_genesis 27 *
mp-wp_genesis 28 * @param string $id Importer tag. Used to uniquely identify importer.
mp-wp_genesis 29 * @param string $name Importer name and title.
mp-wp_genesis 30 * @param string $description Importer description.
mp-wp_genesis 31 * @param callback $callback Callback to run.
mp-wp_genesis 32 * @return WP_Error Returns WP_Error when $callback is WP_Error.
mp-wp_genesis 33 */
mp-wp_genesis 34 function register_importer( $id, $name, $description, $callback ) {
mp-wp_genesis 35 global $wp_importers;
mp-wp_genesis 36 if ( is_wp_error( $callback ) )
mp-wp_genesis 37 return $callback;
mp-wp_genesis 38 $wp_importers[$id] = array ( $name, $description, $callback );
mp-wp_genesis 39 }
mp-wp_genesis 40
mp-wp_genesis 41 /**
mp-wp_genesis 42 * Cleanup importer.
mp-wp_genesis 43 *
mp-wp_genesis 44 * Removes attachment based on ID.
mp-wp_genesis 45 *
mp-wp_genesis 46 * @since 2.0.0
mp-wp_genesis 47 *
mp-wp_genesis 48 * @param string $id Importer ID.
mp-wp_genesis 49 */
mp-wp_genesis 50 function wp_import_cleanup( $id ) {
mp-wp_genesis 51 wp_delete_attachment( $id );
mp-wp_genesis 52 }
mp-wp_genesis 53
mp-wp_genesis 54 /**
mp-wp_genesis 55 * Handle importer uploading and add attachment.
mp-wp_genesis 56 *
mp-wp_genesis 57 * @since 2.0.0
mp-wp_genesis 58 *
mp-wp_genesis 59 * @return array
mp-wp_genesis 60 */
mp-wp_genesis 61 function wp_import_handle_upload() {
mp-wp_genesis 62 $overrides = array( 'test_form' => false, 'test_type' => false );
mp-wp_genesis 63 $_FILES['import']['name'] .= '.import';
mp-wp_genesis 64 $file = wp_handle_upload( $_FILES['import'], $overrides );
mp-wp_genesis 65
mp-wp_genesis 66 if ( isset( $file['error'] ) )
mp-wp_genesis 67 return $file;
mp-wp_genesis 68
mp-wp_genesis 69 $url = $file['url'];
mp-wp_genesis 70 $type = $file['type'];
mp-wp_genesis 71 $file = addslashes( $file['file'] );
mp-wp_genesis 72 $filename = basename( $file );
mp-wp_genesis 73
mp-wp_genesis 74 // Construct the object array
mp-wp_genesis 75 $object = array( 'post_title' => $filename,
mp-wp_genesis 76 'post_content' => $url,
mp-wp_genesis 77 'post_mime_type' => $type,
mp-wp_genesis 78 'guid' => $url
mp-wp_genesis 79 );
mp-wp_genesis 80
mp-wp_genesis 81 // Save the data
mp-wp_genesis 82 $id = wp_insert_attachment( $object, $file );
mp-wp_genesis 83
mp-wp_genesis 84 return array( 'file' => $file, 'id' => $id );
mp-wp_genesis 85 }
mp-wp_genesis 86
mp-wp_genesis 87 ?>