web/wp-admin/includes/import.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    87 
    87 
    88 	// Save the data
    88 	// Save the data
    89 	$id = wp_insert_attachment( $object, $file );
    89 	$id = wp_insert_attachment( $object, $file );
    90 
    90 
    91 	// schedule a cleanup for one day from now in case of failed import or missing wp_import_cleanup() call
    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 ) );
    92 	wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
    93 
    93 
    94 	return array( 'file' => $file, 'id' => $id );
    94 	return array( 'file' => $file, 'id' => $id );
    95 }
    95 }
       
    96 
       
    97 /**
       
    98  * Returns a list from WordPress.org of popular importer plugins.
       
    99  *
       
   100  * @since 3.5.0
       
   101  *
       
   102  * @return array Importers with metadata for each.
       
   103  */
       
   104 function wp_get_popular_importers() {
       
   105 	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
       
   106 
       
   107 	$locale = get_locale();
       
   108 	$popular_importers = get_site_transient( 'popular_importers_' . $locale );
       
   109 
       
   110 	if ( ! $popular_importers ) {
       
   111 		$url = add_query_arg( 'locale', get_locale(), 'http://api.wordpress.org/core/importers/1.0/' );
       
   112 		$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() );
       
   113 		$popular_importers = maybe_unserialize( wp_remote_retrieve_body( wp_remote_get( $url, $options ) ) );
       
   114 
       
   115 		if ( is_array( $popular_importers ) )
       
   116 			set_site_transient( 'popular_importers_' . $locale, $popular_importers, 2 * DAY_IN_SECONDS );
       
   117 		else
       
   118 			$popular_importers = false;
       
   119 	}
       
   120 
       
   121 	if ( is_array( $popular_importers ) ) {
       
   122 		// If the data was received as translated, return it as-is.
       
   123 		if ( $popular_importers['translated'] )
       
   124 			return $popular_importers['importers'];
       
   125 
       
   126 		foreach ( $popular_importers['importers'] as &$importer ) {
       
   127 			$importer['description'] = translate( $importer['description'] );
       
   128 			if ( $importer['name'] != 'WordPress' )
       
   129 				$importer['name'] = translate( $importer['name'] );
       
   130 		}
       
   131 		return $popular_importers['importers'];
       
   132 	}
       
   133 
       
   134 	return array(
       
   135 		// slug => name, description, plugin slug, and register_importer() slug
       
   136 		'blogger' => array(
       
   137 			'name' => __( 'Blogger' ),
       
   138 			'description' => __( 'Install the Blogger importer to import posts, comments, and users from a Blogger blog.' ),
       
   139 			'plugin-slug' => 'blogger-importer',
       
   140 			'importer-id' => 'blogger',
       
   141 		),
       
   142 		'wpcat2tag' => array(
       
   143 			'name' => __( 'Categories and Tags Converter' ),
       
   144 			'description' => __( 'Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.' ),
       
   145 			'plugin-slug' => 'wpcat2tag-importer',
       
   146 			'importer-id' => 'wp-cat2tag',
       
   147 		),
       
   148 		'livejournal' => array(
       
   149 			'name' => __( 'LiveJournal' ),
       
   150 			'description' => __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ),
       
   151 			'plugin-slug' => 'livejournal-importer',
       
   152 			'importer-id' => 'livejournal',
       
   153 		),
       
   154 		'movabletype' => array(
       
   155 			'name' => __( 'Movable Type and TypePad' ),
       
   156 			'description' => __( 'Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.' ),
       
   157 			'plugin-slug' => 'movabletype-importer',
       
   158 			'importer-id' => 'mt',
       
   159 		),
       
   160 		'opml' => array(
       
   161 			'name' => __( 'Blogroll' ),
       
   162 			'description' => __( 'Install the blogroll importer to import links in OPML format.' ),
       
   163 			'plugin-slug' => 'opml-importer',
       
   164 			'importer-id' => 'opml',
       
   165 		),
       
   166 		'rss' => array(
       
   167 			'name' => __( 'RSS' ),
       
   168 			'description' => __( 'Install the RSS importer to import posts from an RSS feed.' ),
       
   169 			'plugin-slug' => 'rss-importer',
       
   170 			'importer-id' => 'rss',
       
   171 		),
       
   172 		'tumblr' => array(
       
   173 			'name' => __( 'Tumblr' ),
       
   174 			'description' => __( 'Install the Tumblr importer to import posts & media from Tumblr using their API.' ),
       
   175 			'plugin-slug' => 'tumblr-importer',
       
   176 			'importer-id' => 'tumblr',
       
   177 		),
       
   178 		'wordpress' => array(
       
   179 			'name' => 'WordPress',
       
   180 			'description' => __( 'Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
       
   181 			'plugin-slug' => 'wordpress-importer',
       
   182 			'importer-id' => 'wordpress',
       
   183 		),
       
   184 	);
       
   185 }