wp/wp-admin/includes/import.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     9 /**
     9 /**
    10  * Retrieve list of importers.
    10  * Retrieve list of importers.
    11  *
    11  *
    12  * @since 2.0.0
    12  * @since 2.0.0
    13  *
    13  *
       
    14  * @global array $wp_importers
    14  * @return array
    15  * @return array
    15  */
    16  */
    16 function get_importers() {
    17 function get_importers() {
    17 	global $wp_importers;
    18 	global $wp_importers;
    18 	if ( is_array( $wp_importers ) ) {
    19 	if ( is_array( $wp_importers ) ) {
    40 /**
    41 /**
    41  * Register importer for WordPress.
    42  * Register importer for WordPress.
    42  *
    43  *
    43  * @since 2.0.0
    44  * @since 2.0.0
    44  *
    45  *
    45  * @param string $id Importer tag. Used to uniquely identify importer.
    46  * @global array $wp_importers
    46  * @param string $name Importer name and title.
    47  *
    47  * @param string $description Importer description.
    48  * @param string   $id          Importer tag. Used to uniquely identify importer.
    48  * @param callback $callback Callback to run.
    49  * @param string   $name        Importer name and title.
       
    50  * @param string   $description Importer description.
       
    51  * @param callable $callback    Callback to run.
    49  * @return WP_Error Returns WP_Error when $callback is WP_Error.
    52  * @return WP_Error Returns WP_Error when $callback is WP_Error.
    50  */
    53  */
    51 function register_importer( $id, $name, $description, $callback ) {
    54 function register_importer( $id, $name, $description, $callback ) {
    52 	global $wp_importers;
    55 	global $wp_importers;
    53 	if ( is_wp_error( $callback ) )
    56 	if ( is_wp_error( $callback ) )
   120  * @return array Importers with metadata for each.
   123  * @return array Importers with metadata for each.
   121  */
   124  */
   122 function wp_get_popular_importers() {
   125 function wp_get_popular_importers() {
   123 	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
   126 	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
   124 
   127 
   125 	$locale = get_locale();
   128 	$locale = get_user_locale();
   126 	$popular_importers = get_site_transient( 'popular_importers_' . $locale );
   129 	$cache_key = 'popular_importers_' . md5( $locale . $wp_version );
       
   130 	$popular_importers = get_site_transient( $cache_key );
   127 
   131 
   128 	if ( ! $popular_importers ) {
   132 	if ( ! $popular_importers ) {
   129 		$url = add_query_arg( 'locale', get_locale(), 'http://api.wordpress.org/core/importers/1.1/' );
   133 		$url = add_query_arg( array(
   130 		$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() );
   134 			'locale'  => $locale,
       
   135 			'version' => $wp_version,
       
   136 		), 'http://api.wordpress.org/core/importers/1.1/' );
       
   137 		$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
       
   138 
       
   139 		if ( wp_http_supports( array( 'ssl' ) ) ) {
       
   140 			$url = set_url_scheme( $url, 'https' );
       
   141 		}
       
   142 
   131 		$response = wp_remote_get( $url, $options );
   143 		$response = wp_remote_get( $url, $options );
   132 		$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );
   144 		$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );
   133 
   145 
   134 		if ( is_array( $popular_importers ) )
   146 		if ( is_array( $popular_importers ) ) {
   135 			set_site_transient( 'popular_importers_' . $locale, $popular_importers, 2 * DAY_IN_SECONDS );
   147 			set_site_transient( $cache_key, $popular_importers, 2 * DAY_IN_SECONDS );
   136 		else
   148 		} else {
   137 			$popular_importers = false;
   149 			$popular_importers = false;
       
   150 		}
   138 	}
   151 	}
   139 
   152 
   140 	if ( is_array( $popular_importers ) ) {
   153 	if ( is_array( $popular_importers ) ) {
   141 		// If the data was received as translated, return it as-is.
   154 		// If the data was received as translated, return it as-is.
   142 		if ( $popular_importers['translated'] )
   155 		if ( $popular_importers['translated'] )
   152 
   165 
   153 	return array(
   166 	return array(
   154 		// slug => name, description, plugin slug, and register_importer() slug
   167 		// slug => name, description, plugin slug, and register_importer() slug
   155 		'blogger' => array(
   168 		'blogger' => array(
   156 			'name' => __( 'Blogger' ),
   169 			'name' => __( 'Blogger' ),
   157 			'description' => __( 'Install the Blogger importer to import posts, comments, and users from a Blogger blog.' ),
   170 			'description' => __( 'Import posts, comments, and users from a Blogger blog.' ),
   158 			'plugin-slug' => 'blogger-importer',
   171 			'plugin-slug' => 'blogger-importer',
   159 			'importer-id' => 'blogger',
   172 			'importer-id' => 'blogger',
   160 		),
   173 		),
   161 		'wpcat2tag' => array(
   174 		'wpcat2tag' => array(
   162 			'name' => __( 'Categories and Tags Converter' ),
   175 			'name' => __( 'Categories and Tags Converter' ),
   163 			'description' => __( 'Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.' ),
   176 			'description' => __( 'Convert existing categories to tags or tags to categories, selectively.' ),
   164 			'plugin-slug' => 'wpcat2tag-importer',
   177 			'plugin-slug' => 'wpcat2tag-importer',
   165 			'importer-id' => 'wp-cat2tag',
   178 			'importer-id' => 'wp-cat2tag',
   166 		),
   179 		),
   167 		'livejournal' => array(
   180 		'livejournal' => array(
   168 			'name' => __( 'LiveJournal' ),
   181 			'name' => __( 'LiveJournal' ),
   169 			'description' => __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ),
   182 			'description' => __( 'Import posts from LiveJournal using their API.' ),
   170 			'plugin-slug' => 'livejournal-importer',
   183 			'plugin-slug' => 'livejournal-importer',
   171 			'importer-id' => 'livejournal',
   184 			'importer-id' => 'livejournal',
   172 		),
   185 		),
   173 		'movabletype' => array(
   186 		'movabletype' => array(
   174 			'name' => __( 'Movable Type and TypePad' ),
   187 			'name' => __( 'Movable Type and TypePad' ),
   175 			'description' => __( 'Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.' ),
   188 			'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ),
   176 			'plugin-slug' => 'movabletype-importer',
   189 			'plugin-slug' => 'movabletype-importer',
   177 			'importer-id' => 'mt',
   190 			'importer-id' => 'mt',
   178 		),
   191 		),
   179 		'opml' => array(
   192 		'opml' => array(
   180 			'name' => __( 'Blogroll' ),
   193 			'name' => __( 'Blogroll' ),
   181 			'description' => __( 'Install the blogroll importer to import links in OPML format.' ),
   194 			'description' => __( 'Import links in OPML format.' ),
   182 			'plugin-slug' => 'opml-importer',
   195 			'plugin-slug' => 'opml-importer',
   183 			'importer-id' => 'opml',
   196 			'importer-id' => 'opml',
   184 		),
   197 		),
   185 		'rss' => array(
   198 		'rss' => array(
   186 			'name' => __( 'RSS' ),
   199 			'name' => __( 'RSS' ),
   187 			'description' => __( 'Install the RSS importer to import posts from an RSS feed.' ),
   200 			'description' => __( 'Import posts from an RSS feed.' ),
   188 			'plugin-slug' => 'rss-importer',
   201 			'plugin-slug' => 'rss-importer',
   189 			'importer-id' => 'rss',
   202 			'importer-id' => 'rss',
   190 		),
   203 		),
   191 		'tumblr' => array(
   204 		'tumblr' => array(
   192 			'name' => __( 'Tumblr' ),
   205 			'name' => __( 'Tumblr' ),
   193 			'description' => __( 'Install the Tumblr importer to import posts & media from Tumblr using their API.' ),
   206 			'description' => __( 'Import posts & media from Tumblr using their API.' ),
   194 			'plugin-slug' => 'tumblr-importer',
   207 			'plugin-slug' => 'tumblr-importer',
   195 			'importer-id' => 'tumblr',
   208 			'importer-id' => 'tumblr',
   196 		),
   209 		),
   197 		'wordpress' => array(
   210 		'wordpress' => array(
   198 			'name' => 'WordPress',
   211 			'name' => 'WordPress',
   199 			'description' => __( 'Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
   212 			'description' => __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
   200 			'plugin-slug' => 'wordpress-importer',
   213 			'plugin-slug' => 'wordpress-importer',
   201 			'importer-id' => 'wordpress',
   214 			'importer-id' => 'wordpress',
   202 		),
   215 		),
   203 	);
   216 	);
   204 }
   217 }