2007-05-25 03:16:21 -04:00
|
|
|
<?php
|
2008-10-01 21:03:26 -04:00
|
|
|
/**
|
|
|
|
* WordPress Administration Importer API.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
2007-05-25 03:16:21 -04:00
|
|
|
|
2008-10-01 21:03:26 -04:00
|
|
|
/**
|
2008-10-10 14:21:16 -04:00
|
|
|
* Retrieve list of importers.
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @since 2.0.0
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @return array
|
2008-10-01 21:03:26 -04:00
|
|
|
*/
|
2007-05-25 03:16:21 -04:00
|
|
|
function get_importers() {
|
|
|
|
global $wp_importers;
|
2007-12-19 12:48:51 -05:00
|
|
|
if ( is_array($wp_importers) )
|
|
|
|
uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
|
2007-05-25 03:16:21 -04:00
|
|
|
return $wp_importers;
|
|
|
|
}
|
|
|
|
|
2008-10-01 21:03:26 -04:00
|
|
|
/**
|
2008-10-10 14:21:16 -04:00
|
|
|
* Register importer for WordPress.
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @since 2.0.0
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @param string $id Importer tag. Used to uniquely identify importer.
|
|
|
|
* @param string $name Importer name and title.
|
|
|
|
* @param string $description Importer description.
|
|
|
|
* @param callback $callback Callback to run.
|
|
|
|
* @return WP_Error Returns WP_Error when $callback is WP_Error.
|
2008-10-01 21:03:26 -04:00
|
|
|
*/
|
2007-05-25 03:16:21 -04:00
|
|
|
function register_importer( $id, $name, $description, $callback ) {
|
|
|
|
global $wp_importers;
|
2007-09-18 12:32:22 -04:00
|
|
|
if ( is_wp_error( $callback ) )
|
|
|
|
return $callback;
|
2007-05-25 03:16:21 -04:00
|
|
|
$wp_importers[$id] = array ( $name, $description, $callback );
|
|
|
|
}
|
|
|
|
|
2008-10-01 21:03:26 -04:00
|
|
|
/**
|
2008-10-10 14:21:16 -04:00
|
|
|
* Cleanup importer.
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* Removes attachment based on ID.
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @since 2.0.0
|
|
|
|
*
|
|
|
|
* @param string $id Importer ID.
|
2008-10-01 21:03:26 -04:00
|
|
|
*/
|
2007-05-25 03:16:21 -04:00
|
|
|
function wp_import_cleanup( $id ) {
|
|
|
|
wp_delete_attachment( $id );
|
|
|
|
}
|
|
|
|
|
2008-10-01 21:03:26 -04:00
|
|
|
/**
|
2008-10-10 14:21:16 -04:00
|
|
|
* Handle importer uploading and add attachment.
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @since 2.0.0
|
2008-10-01 21:03:26 -04:00
|
|
|
*
|
2008-10-10 14:21:16 -04:00
|
|
|
* @return array
|
2008-10-01 21:03:26 -04:00
|
|
|
*/
|
2007-05-25 03:16:21 -04:00
|
|
|
function wp_import_handle_upload() {
|
|
|
|
$overrides = array( 'test_form' => false, 'test_type' => false );
|
2007-12-24 01:20:34 -05:00
|
|
|
$_FILES['import']['name'] .= '.import';
|
2007-05-25 03:16:21 -04:00
|
|
|
$file = wp_handle_upload( $_FILES['import'], $overrides );
|
|
|
|
|
|
|
|
if ( isset( $file['error'] ) )
|
|
|
|
return $file;
|
|
|
|
|
|
|
|
$url = $file['url'];
|
|
|
|
$type = $file['type'];
|
|
|
|
$file = addslashes( $file['file'] );
|
|
|
|
$filename = basename( $file );
|
|
|
|
|
|
|
|
// Construct the object array
|
|
|
|
$object = array( 'post_title' => $filename,
|
|
|
|
'post_content' => $url,
|
|
|
|
'post_mime_type' => $type,
|
|
|
|
'guid' => $url
|
|
|
|
);
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
$id = wp_insert_attachment( $object, $file );
|
|
|
|
|
|
|
|
return array( 'file' => $file, 'id' => $id );
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|